我有一个闪亮的应用程序,我试图只有选中了复选框时才会出现两个滑块。下面是我试图开始工作的代码,但没有看到UI。
library(shiny)
ui <- fluidPage(
checkboxInput("box_checked", "box_checked", value = FALSE),
uiOutput("test")
)
# Define server logic
server <- function(input, output) {
output$test = renderUI({
if (input$box_checked = 0){
return(NULL)
}
if(input$box_checked = 1){
sliderInput("sliderOne", "Choose your value", min=0, max=100, value=50)
sliderInput("sliderTwo", "Choose your other value", min=0, max=50, value=25)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
尝试这种方式:
library(shiny)
ui <- fluidPage(checkboxInput("box_checked", "box_checked", value = FALSE),
uiOutput("test"))
# Define server logic
server <- function(input, output) {
output$test = renderUI({
if (input$box_checked == 0) {
return(NULL)
}
if (input$box_checked == 1) {
list(
sliderInput(
"sliderOne",
"Choose your value",
min = 0,
max = 100,
value = 50
),
sliderInput(
"sliderTwo",
"Choose your other value",
min = 0,
max = 50,
value = 25
)
)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
if
语句,因为您使用的是input$box_checked = 1
而不是input$box_checked == 1
。 list()
在renderUI
内生成多个UI元素。