【问题标题】:checkboxGroupInput with options for each tick (multiple possible ticks)checkboxGroupInput 带有每个刻度的选项(多个可能的刻度)
【发布时间】:2020-09-11 04:08:42
【问题描述】:

我是 Shiny 的新手,如果我的问题看起来很明显,我很抱歉。我将非常感谢您对此事的任何帮助。

我使用checkboxGroupInput 进行多项选择(例如星期几),我需要为每个刻度显示选项(例如小时)。

我尝试为每个选项添加conditionalPanel。但这仅在仅勾选一个框时才有效。如果勾选了两个或更多框,则不显示任何选项。 此外,条件选项出现在所有checkboxGroupInput 块的底部。

理想情况下,我希望checkboxGroupInput 的选项垂直显示(这是默认设置),并且对于每个勾选的选项,selectInput(或等效的checkboxGroupInput)出现在勾选选项的右侧带有条件值。

我希望我的问题足够清楚,并且实施起来不会太难!

非常感谢您的帮助:-)

shinyApp(

  ui = fluidPage(
    titlePanel("Week and time"),
    div(
      id = "form",
      checkboxGroupInput("days", "Days of week",
                  c("Monday", "Tuesday", "Wenesday")),
      conditionalPanel(condition = "input.days == 'Monday'",
                       selectInput("time",
                                   "Hours to choose Monday", 
                                   c("8h00", "9h00"))),
      conditionalPanel(condition = "input.days == 'Tuesday'",
                       selectInput("time",
                                   "Hours to choose Tuesday", 
                                   c("8h00", "9h00"))),
      actionButton("submit", "Submit", class = "btn-primary")
    )
  ),
  server = function(input, output, session) {
  }
)

【问题讨论】:

  • 这个答案对你有帮助吗?如果是这样,请将其标记为已接受,以表示社区知道它。否则,请指出缺少的内容。谢谢!
  • @mnist 我尝试了代码,但结果并不完全符合我的预期......无论如何,我知道在 SO 上获得积分有多难!
  • 遗漏了什么?

标签: javascript r shiny shinyapps


【解决方案1】:

您在这里将两个问题嵌套在一起。关于第一个(“如何检查radioButton 是否被点击”),这是一个纯 JavaScript 问题。我从here那里得到了解决方案。

关于对齐:这比较棘手。我向您展示了一个简单的方法,它只有两个 conditionalPanels,大约。相同的垂直空间,因此其他对象不会上下跳跃。如果您想完全控制它,请使用单个复选框。在一行中有一个复选框和selectInput。例如,在服务器中,您可以将它们放在reactiveValues 中。

取决于你更难实现的代码结构



shinyApp(

  ui = fluidPage(
    titlePanel("Week and time"),
    fluidRow(column(
      id = "form",
      width = 3,
      checkboxGroupInput("days", "Days of week",
                         c(HTML("Monday"), "Tuesday", "Wenesday"))),
      column(width = 9,
             # check whether Monday is in input.days
             conditionalPanel(condition = "input.days.indexOf('Monday') > -1",
                              selectInput("time",
                                          "Hours to choose Monday", 
                                          c("8h00", "9h00"))),
             # if Monday is not in input.days, show a div with the same size as the
             # selectInput
             conditionalPanel(condition = "input.days.indexOf('Monday') == -1",
                              div(style = "height:70px")),
             # check whether Tuesday is in input.days
             conditionalPanel(condition = "input.days.indexOf('Tuesday') > -1",
                              selectInput("time",
                                          "Hours to choose Tuesday", 
                                          c("8h00", "9h00"))),
             # if Tuesday is not in input.days, show a div with the same size as the
             # selectInput
             conditionalPanel(condition = "input.days.indexOf('Tuesday') == -1",
                              div(style = "height:70px"))
      )),
    fluidRow(actionButton("submit", "Submit", class = "btn-primary"))

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    相关资源
    最近更新 更多