【问题标题】:r shiny conditional displayr 闪亮的条件显示
【发布时间】:2014-06-16 23:57:37
【问题描述】:

我想根据复选框组中选择的值的数量以两种不同的方式显示单选按钮。 例如,如果我的复选框代码是:

     checkboxGroupInput("ctype","Claim Type:" , c("CC" = "cc", "mc" = "mc", "md" = "md"), selected = NULL)

如果只选择了一个 ctype,那么我想显示以下内容:

    radioButtons("bygroup", "By Group",c("Size(GB)" = "Size.bytes."),selected = "Size.bytes.")

如果选择了多个 ctype,那么我想显示以下内容:

    radioButtons("bygroup", "By Group",c("Size(GB)" = "Size.bytes.", "Record Count(Mil)" = "Record_count", "PC(Mil)" ="UEC"),selected = "Size.bytes."))

我在条件面板中尝试了以下条件:

    conditionalPanel("length(input.ctype) > 1",radioButtons("bygroup",.....

没用,有什么建议....

【问题讨论】:

  • 我尝试了 server.R 的 renderUI 并且它可以工作,但如果可能的话,我想从 ui.R 本身执行此操作。
  • length 不是 javascript 函数。使用input.cytpe.length

标签: r user-interface conditional-statements shiny


【解决方案1】:

条件需要用javascript编写。 length(input.ctype) 应该是 input.cytpe.length

runApp(list(
  ui = bootstrapPage(
    checkboxGroupInput("ctype","Claim Type:" , c("CC" = "cc", "mc" = "mc", "md" = "md"), selected = NULL),
    conditionalPanel("input.ctype.length > 1",
                     radioButtons("bygroup", "By Group",c("Size(GB)" = "Size.bytes."),selected = "Size.bytes.")
    ),
    conditionalPanel("input.ctype.length <= 1",
                     radioButtons("bygroup", "By Group",c("Size(GB)" = "Size.bytes.", "Record Count(Mil)" = "Record_count", "PC(Mil)" ="UEC"),selected = "Size.bytes."))

  ),
  server = function(input, output) {
    output$plot <- renderPlot({ hist(runif(input$n)) })
  }
))

【讨论】:

  • @user2382845 如果给定的答案被认为合适,请考虑将其标记为已回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
  • 2018-03-23
相关资源
最近更新 更多