checkboxGroupInput 带有每个刻度的选项(多个可能的刻度)

checkboxGroupInput with options for each tick (multiple possible ticks)

我是 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) {
  }
)

你在这里嵌套了两个问题。关于第一个("How to check whether the radioButton is clicked"),这是一个纯粹的JavaScript问题。我从 here.

中获取了解决方案

关于对齐:这比较棘手。我向您展示了一种简单的方法,它只有两个 conditionalPanels 和大约。同样垂直space所以其他物体不会上下跳动。如果您想完全控制它,请使用单个复选框。在一行中有一个复选框和 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) {
  }
)