短划线是闪亮ID中的特殊字符吗?

时间:2017-06-06 13:09:56

标签: r shiny

我正在尝试使用conditionalPanel来隐藏某些ui元素。我发现在条件语句中使用的input元素的id中使用“ - ”会导致condtionalPanel中断。这是预期的行为吗?我原本认为“ - ”字符在闪亮的ID中是允许的。

工作示例(从'file-Opt'和'input.file-Opt'中删除“ - ”以使条件面板再次工作。

library(shiny)

ui <- shinyUI(fluidPage(
  fileInput('file', 'Choose file to upload',
    accept = c(
      'text/csv',
      'text/comma-separated-values',
      'text/tab-separated-values',
      'text/plain',
      '.csv',
      '.tsv'
    )
  ),
  checkboxInput('file-Opt', "Show advanced file options", FALSE),
  tags$hr(),
  conditionalPanel(
    condition = 'input.file-Opt == true',
    checkboxInput('header', 'Header', TRUE)
  ) # conditionalPanel close
))

server <- shinyServer(function(input, output, session) {

})

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

建议您不要在输入ID中使用特殊的JavaScript字符,例如句点.,但如果您确实使用它们,例如inputId = "foo.bar",则必须使用{{ 1}}而不是input["foo.bar"]来读取输入值。 我想“ - ”也是如此。

来源: https://shiny.rstudio.com/reference/shiny/latest/conditionalPanel.html