I am attempting to use the pickerInput to make multiple selections of the different variables. When I make selections, "select all", only one item is displated, i.e. the first row "Mazda RX4" . It seems I am missing something on the server side of things that will connect multiple selections to show more than one row that meets the required criteria when selecting multiple variables and getting more than one row.
Here is my example:
library(shiny)
library(shinyWidgets)
library(DT)
library(dplyr)
mtcars <- mtcars[, c(1:5)]
mpg <- mtcars[,2]
cyl <- mtcars[,3]
disp <- mtcars[,4]
hp <- mtcars[,5]
ui <- fluidPage(
# Application title
titlePanel("Cars Information"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "mpg",
label = "Choose MPG:",
choices = c(unique(mtcars$mpg)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "cyl",
label = "Choose a cylinder:",
choices = c(unique(mtcars$cyl)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "disp",
label = "Choose a Displacement:",
choices = c(unique(mtcars$disp)),
options = list(`actions-box` = TRUE),multiple = T),
pickerInput(inputId = "hp",
label = "Choose a weight:",
choices = c(unique(mtcars$hp)),
options = list(`actions-box` = TRUE),multiple = T),
actionButton("view", "View Selection")
),
mainPanel(
DTOutput(outputId = "table")
)
)
)
# Define server logic
server <- function(input, output) {
datasetInput <- eventReactive(input$view,{
datasetInput <- filter(mtcars, mpg == input$mpg, cyl == input$cyl,
disp == input$disp, hp == input$hp)
return(datasetInput)
})
output$table <- renderDT({datasetInput()
}, colnames = c("Car Make/Model", "Miles per Gallon", "Cylinders", "Displacement", "Weight"))
}
# Run the application
shinyApp(ui = ui, server = server)