如何在 R Shiny 中使两个菜单相关或分层?
how to make two menu dependent or hierarchical in Rshiny?
我在 UI 中有两个输入菜单。一个是案例菜单,第二个是滑块菜单。
我想在单击案例菜单和 select 滑块 1 时显示。它只显示滑块菜单 slider1 ,当我单击案例菜单和 select 滑块 2 时。它只显示 slider2 的滑块菜单。
ui <- fluidPage(
fluidRow(
column(5,
selectInput("case", "case",c("slider1"="slider1","slider2"="slider2"
))),
column(5,
sliderInput("slider1", "slider1",
min = 0, max = 9, value = 5)),
column(5,
sliderInput("slider2", "slider2",
min = 0, max = 20, value = 2))
))
server <- function(input, output) {}
# Run the application
shinyApp(ui = ui, server = server)
你可以在这里使用conditionalPanel
。这将根据 Javascript 表达式的值创建一个可见或不可见的面板。在这种情况下,您的表达式将检查 input.case
的值,selectInput
以选择您想要的滑块。
library(shiny)
ui <- fluidPage(
fluidRow(
column(5,
selectInput("case", "case", c("slider1" = "slider1", "slider2" = "slider2"
))),
conditionalPanel(
condition = "input.case == 'slider1'",
column(5,
sliderInput("slider1", "slider1",
min = 0, max = 9, value = 5))),
conditionalPanel(
condition = "input.case == 'slider2'",
column(5,
sliderInput("slider2", "slider2",
min = 0, max = 20, value = 2)))
)
)
我在 UI 中有两个输入菜单。一个是案例菜单,第二个是滑块菜单。
我想在单击案例菜单和 select 滑块 1 时显示。它只显示滑块菜单 slider1 ,当我单击案例菜单和 select 滑块 2 时。它只显示 slider2 的滑块菜单。
ui <- fluidPage(
fluidRow(
column(5,
selectInput("case", "case",c("slider1"="slider1","slider2"="slider2"
))),
column(5,
sliderInput("slider1", "slider1",
min = 0, max = 9, value = 5)),
column(5,
sliderInput("slider2", "slider2",
min = 0, max = 20, value = 2))
))
server <- function(input, output) {}
# Run the application
shinyApp(ui = ui, server = server)
你可以在这里使用conditionalPanel
。这将根据 Javascript 表达式的值创建一个可见或不可见的面板。在这种情况下,您的表达式将检查 input.case
的值,selectInput
以选择您想要的滑块。
library(shiny)
ui <- fluidPage(
fluidRow(
column(5,
selectInput("case", "case", c("slider1" = "slider1", "slider2" = "slider2"
))),
conditionalPanel(
condition = "input.case == 'slider1'",
column(5,
sliderInput("slider1", "slider1",
min = 0, max = 9, value = 5))),
conditionalPanel(
condition = "input.case == 'slider2'",
column(5,
sliderInput("slider2", "slider2",
min = 0, max = 20, value = 2)))
)
)