【问题标题】:R shiny: how to specify a selectInput in html?R闪亮:如何在html中指定一个selectInput?
【发布时间】:2014-03-10 16:26:24
【问题描述】:

我需要在 html 中指定一些 selectInput()(以便将它们插入数据框中)。

下面的可重现代码没有为我提供 selectInput。 HTML() 中的内容是我使用“检查元素”获得的 selectInput() 的 html 代码的复制粘贴(这可能是它不起作用的原因,但不幸的是我无法修复它)

shiny::runApp(
list(
ui = pageWithSidebar(

headerPanel("TEST"),

sidebarPanel(
helpText('This does not work:')
),

mainPanel(    
HTML("<label class='control-label' for='variable' style = 'width:400px;'>Variable:</label>
<select id='variable' tabindex='-1' class='selectized shiny-bound-input' style='display: none;'><option value='toz' selected='selected'></option></select>  
<div class='selectize-control single'><div class='selectize-input items full has-options has-items'><div data-value='toz' class='item'>Cyl</div><input type='text' autocomplete='off' tabindex='' style='width: 4px; opacity: 0; position: absolute; left: -10000px;'></div><div class='selectize-dropdown single' style='display: none; width: 893px; top: 36px; left: 0px; visibility: visible;'><div class='selectize-dropdown-content'><div data-value='toz' data-selectable='' class='option selected'>Cyl</div><div data-value='toztoz' data-selectable='' class='option'>Trans</div><div data-value='ge' data-selectable='' class='option'>Gea</div></div></div></div>
<script data-for='variable' type='application/json'>{}</script>")   

)
)
, 

server = function(input,output){      
}
)
)

提前谢谢你 干杯

【问题讨论】:

  • 你不能从网页中随机复制代码并期望它做你想做的事情:/
  • 请提供您的实际代码或可重现的示例、除了“这里出了什么问题”之外的更具体的问题,和/或您迄今为止尝试过的事情

标签: html r shiny


【解决方案1】:

检查源代码对于了解它是如何构建的非常有用,但是我不建议您复制整个代码部分以按原样重复使用。使用闪亮的功能。

但是如果你想用 HTML 语法构建你的选择输入,你可以简单地使用 HTML 选择标签:

mainPanel(    
  HTML("<select id='select'>
          <option value='cyl'>Cyl</option>
          <option value='trans'>Trans</option>
          <option value='gea'>Gea</option>
        </select>")
)

顺便说一句,在您复制的代码中:style='display: none;' 隐藏元素(但无论如何此代码无法按原样工作)。

【讨论】:

  • 太棒了!谢谢 !我认为我在慢慢进步/我一天比一天了解更多,这也感谢您的回答!
猜你喜欢
  • 2015-05-07
  • 2016-08-12
  • 2018-07-25
  • 2016-07-28
  • 2018-05-25
  • 2018-09-21
  • 2018-07-09
  • 1970-01-01
  • 2016-01-09
相关资源
最近更新 更多