r-覆盖selectInput values using复选框



我很难找到合适的术语来搜索这个词。我有一个Shiny应用程序,它有两个滑块,为应用程序的服务器部分提供输入值。我希望用户可以选择调整滑动条(场景A(,或者选中一个框/单击一个按钮,直接进入场景B。场景B会设置用户不需要知道的输入。

如果我们使用这个例子,添加会让用户选中一个框,上面写着";我不想选择"如果我们将默认值设置为MN,则勾选该框将导致显示"MN"的结果;您选择了MN";。

if (interactive()) {

# basic example
shinyApp(
ui = fluidPage(
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
tableOutput("data")
),
server = function(input, output) {
output$data <- renderTable({
mtcars[, c("mpg", input$variable), drop = FALSE]
}, rownames = TRUE)
}
)

# demoing group support in the `choices` arg
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a state:",
list(`East Coast` = list("NY", "NJ", "CT"),
`West Coast` = list("WA", "OR", "CA"),
`Midwest` = list("MN", "WI", "IA"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
}

也许您正在寻找这个。

library(shiny)
library(shinyjs)
shinyApp(
ui = fluidPage(
useShinyjs(),
checkboxInput("wanttochoose", "I don't want to choose", value = FALSE),
sliderInput("slide1", "My value", min=0, max=10, value=3),
selectInput("state", "Choose a state:",
list(`East Coast` = list("NY", "NJ", "CT"),
`West Coast` = list("WA", "OR", "CA"),
`Midwest` = list("MN", "WI", "IA")), 
selected = "MN"
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
observe({
if (input$wanttochoose){
shinyjs::show("slide1")
}else{
shinyjs::hide("slide1")
}

})
}
)

最新更新