如何将材质开关与Shinydashboard一起使用[R]

时间:2018-12-03 09:32:35

标签: r shiny shinydashboard

我知道我缺少明显的东西,但是由于某种原因,我无法使用Shinydashboard在实际的应用程序中进行任何实质性的切换。

我想在侧边栏中使用它来激活另一个输入。但是,使用下面的代码,尽管出现了开关,但是它什么也没做。

我认为密钥可能处于conditionalPanel的条件下...

library("shiny")
library("shinydashboard")
library("shinyWidgets")

sidebar <- dashboardSidebar(materialSwitch(inputId = "check", 
        label = h4("View by options")),
        conditionalPanel(condition = "input.check == TRUE",
        awesomeRadio(inputId = "options", label = NULL, choices = c("A", "B", "C"),
                           selected = c("A"))))

body <- dashboardBody()

ui <- dashboardPage(dashboardHeader(title = "Example"),
                sidebar,
                body
                )

server <- function(input, output) {
}

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:2)

请注意,这是javascript有条件的,因此它不知道TRUE是什么R评估,请将其更改为true

library("shiny")
library("shinydashboard")
library("shinyWidgets")

sidebar <- dashboardSidebar(materialSwitch(inputId = "check", 
                                           label = h4("View by options")),
                            conditionalPanel(condition = "input.check == true",
                                             awesomeRadio(inputId = "options", label = NULL, choices = c("A", "B", "C"),
                                                          selected = c("A"))))

body <- dashboardBody()

ui <- dashboardPage(dashboardHeader(title = "Example"),
                    sidebar,
                    body
)

server <- function(input, output) {
}

shinyApp(ui, server)