HTML shine ui的动态输入(index.html)

时间:2015-08-10 15:40:22

标签: html r shiny

我想用html / css从头开始自定义我的闪亮应用程序。因此我使用index.html而不是ui.r,我遇到了以下问题:

我在我的ui.r中使用动态输入,例如:

selectInput("var","Date",choices = format(Sys.time(),'%Y-%m-%d'))

转换为:

<div class="form-group shiny-input-container">
  <label class="control-label" for="var">Date</label>
  <div>
    <select id="var"><option value="2015-08-10" selected>2015-08-10</option></select>
    <script type="application/json" data-for="var" data-nonempty="">{}</script>
  </div>
</div> 

因为我必须使用Sys.time()而不是html代码中的实际日期,如果甚至可以在仅使用.html为ui调用R / shiny时我很感兴趣?

1 个答案:

答案 0 :(得分:0)

Shiny对此有一个特殊功能:updateSelectInput

在您的ShinyUI中保留choices = NULL或类似choices = "Please Select Something."的内容(如果通过ui.R或index.html生成,则无关紧要)。

然后在server.R内部,调用updateSelectInput将您的choices属性更改为您在反应性上下文中所需的任何内容。

这是一个单文件App中的一些简单代码示例:

app <- shinyApp(

  ui = shinyUI(fluidPage(
    selectInput("inputID", label = "Reactive Select Input." , choices = "Please Select, Monsieur."), 
    actionButton("buttonID", label = "Refresh Select Options.")
  )),

  server = function(session, input, output) {

    observeEvent(input$buttonID, {
      updateSelectInput(session, "inputID", choices = as.character(Sys.time()))
    })

  }
)

享受!

相关问题