I'm trying to use the value(s) of input$levels
in the plot as the title but selectInput
is only displaying the first value when multiple are selected. The plot itself changes in the correct way, which means shiny knows that multiple levels are selected.
library(tidyverse)
library(shiny)
test_data <- data.frame(x = seq(1, 100, 10),
y = seq(1, 100, 10),
level = rep(c(1, 2), 5))
ui <- fluidPage(
titlePanel("Example"),
sidebarLayout(
sidebarPanel(
selectInput("levels",
"Include level(s):",
selected=1,
choices=c(1, 2),
multiple=TRUE)
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output) {
output$plot <- renderPlot({
ggplot(test_data %>%
filter(level %in% input$levels), aes(x, y)) +
geom_point() +
ggtitle(paste("Including level(s):", input$levels))
})
}
shinyApp(ui, server)
How does one access all values of selectInput
when multiple are selected?