如何使用复选框来防止 运行 的某些输出?
How to use checkbox to prevent certain outputs from running?
library(shiny)
ui <- fluidPage(
checkboxGroupInput("data", "Select data:",
c("Iris" = "iris",
"Cars" = "mtcars")),
#####
checkboxGroupInput("display", "Fit to data:",
c("Yes" = "fit",
"No"= "nofit")),
#####
plotOutput("myPlot")
)
server <- function(input, output) {
dat <- reactive({
switch()
})
output$myPlot <- renderPlot({
dat <- switch(input$data,
"iris" = iris,
"mtcars" = mtcars)
plot(Sepal.Width ~ Sepal.Length, data = get(input$data))
})
}
shinyApp(ui, server)
我有一个复选框,让用户决定 s/he 是否希望数据适合。但是,我不确定如何将其应用到我的 server
中。本质上,如果用户在复选框中选择 Yes
,那么我希望程序通过 renderPlot
,否则,请不要打扰。也许另一个 switch
包含了我的 renderPlot
?
只需添加一个开关或 if then 到依赖于 input$display 的 renderPlot() 调用。
output$myPlot <- renderPlot({
if(input$display == 'fit') {
dat <- switch(input$data,
"iris" = iris,
"mtcars" = mtcars)
plot(Sepal.Width ~ Sepal.Length, data = get(input$data))
} else {NULL}
})
library(shiny)
ui <- fluidPage(
checkboxGroupInput("data", "Select data:",
c("Iris" = "iris",
"Cars" = "mtcars")),
#####
checkboxGroupInput("display", "Fit to data:",
c("Yes" = "fit",
"No"= "nofit")),
#####
plotOutput("myPlot")
)
server <- function(input, output) {
dat <- reactive({
switch()
})
output$myPlot <- renderPlot({
dat <- switch(input$data,
"iris" = iris,
"mtcars" = mtcars)
plot(Sepal.Width ~ Sepal.Length, data = get(input$data))
})
}
shinyApp(ui, server)
我有一个复选框,让用户决定 s/he 是否希望数据适合。但是,我不确定如何将其应用到我的 server
中。本质上,如果用户在复选框中选择 Yes
,那么我希望程序通过 renderPlot
,否则,请不要打扰。也许另一个 switch
包含了我的 renderPlot
?
只需添加一个开关或 if then 到依赖于 input$display 的 renderPlot() 调用。
output$myPlot <- renderPlot({
if(input$display == 'fit') {
dat <- switch(input$data,
"iris" = iris,
"mtcars" = mtcars)
plot(Sepal.Width ~ Sepal.Length, data = get(input$data))
} else {NULL}
})