I'd like to use the user-selected variables to filter (and then plot) data. But I'm getting an error that 'list' object cannot be coerced to type 'double'. Here's a dummy example where I'm trying to say: "If user selects "gear" from the list of variables, show a histogram of horsepower for all cars where gear = 4".
library(shiny)
mtcars_cols <- mtcars %>% select(gear, carb)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Motor Car Trend Road Tests"),
# Sidebar
sidebarLayout(
varSelectInput("variables",
"Select variables: ",
mtcars_cols,
multiple = TRUE),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
dt <- mtcars %>%
filter(!!!input$variables == 4)
bins <- seq(min(x), max(x), length.out = 10 + 1)
# draw the histogram with the specified number of bins
hist(dt$hp, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)