闪亮-selectInput和checkboxInput之间的连接

时间:2019-02-28 11:44:12

标签: r shiny shinydashboard

我有一个通过多个标签设计的Shiny App。 在第一个标签中,我有多个selectInputs和复选框。

这些对象应有助于在建筑物内选择级别和/或区域。 该建筑物有多个楼层,每个楼层都有多个区域。

复选框代表是否要选择建筑物的某一层,而selectInputs代表要从该层中选择的特定区域。也就是说:每个级别都有自己的复选框,每个复选框都有自己的selectInput。

这些输入的相关性如下:按下一个复选框时,将选中对应的selectInput的所有选项。

问题是,当我从一个级别(例如,级别0)中选择一个selectInput的某些区域,并且按下另一级别(级别1)的一个复选框后,从(级别0)之前的级别中选择的选项消失了并且不再被选择。 它们似乎以某种方式链接或连接。

有什么办法可以解决此问题?

感谢您的帮助!


以下是应用程序用户界面的相应部分:

tabItem(tabName = "building",
        fluidRow(
          # checkbox for select all levels
          div(class = "selectall", prettyCheckbox(inputId = "selectall", label = strong("All Building Information"), 
                                                  status = "info", shape = "curve")
              )
          ), br(), 
        fluidRow(
          column(
            fluidRow(
              column(
                fluidRow(
                  div(class = "selectlevel", 
                      # checkbox for select level 0
                      prettyCheckbox(inputId = "selectlevel0", label = strong("Level 0"), 
                                     status = "info", animation = "smooth", shape = "curve", plain = T)
                      )
                  ),
                div(class = "sepselect", 
                    fluidRow(
                      # select input level 0 zones
                      selectInput(inputId = "zone0", label = "Select Zone",
                                  choices = c("zone0a","zone0b","zone0c") , multiple = TRUE)
                      )
                    ),
                width = 3),
              column(
                # image level 0 
                img(src = "level0.png", height = "220px", width = "80%", style="border:1px solid grey"),
                width = 9)
            ),
            width = 6),
          column(
            fluidRow(
              column(
                fluidRow(
                  div(class = "selectlevel", 
                      # checkbox for select level 1
                      prettyCheckbox(inputId = "selectlevel1", label = strong("Level 1"), 
                                     status = "info", animation = "smooth", shape = "curve", plain = T)
                      )
                ),
                div(class = "sepselect", 
                    fluidRow(
                      # select input level 1 zones
                      selectInput(inputId = "zone1", label = "Select Zone",
                                  choices = c("zone1a","zone1b","zone1c","zone1d","zone1e"), multiple = TRUE)
                      )
                ),
                width = 3),
              column(
                # image level 1
                img(src = "level1.png", height = "220px", width = "80%", style="border:1px solid grey"),
                width = 9)
            ),
            width = 6)
        )
        ) # close tabitem maps

下面是服务器代码的相应部分:

# select all areas in each level
observe({
# level 0
if(input$selectlevel0 == TRUE){
  selected_choices <- c("zone0a","zone0b","zone0c") 
} else {
  selected_choices <- character(0)
}
updateSelectInput(session, "area0", selected = selected_choices)
# level 1
if(input$selectlevel1 == TRUE){
  selected_choices <- c("zone1a","zone1b","zone1c","zone1d","zone1e")
} else {
  selected_choices <- character(0)
}
updateSelectInput(session, "area1", selected = selected_choices)
})

# select all levels 
observe({
if(input$selectall == FALSE){
  updateCheckboxInput(session, "selectlevel0", value = F)
  updateCheckboxInput(session, "selectlevel1", value = F)
} else{
  updateCheckboxInput(session, "selectlevel0", value = T)
  updateCheckboxInput(session, "selectlevel1", value = T)
}
})

此外,我还为您提供了该应用外观的图片: Partial View of the App

0 个答案:

没有答案