Save Previous Chosen Values In Dropdown Menu In tableOutput In RShiny

Viewed 32

My current app shows the tableOutput based on the chosen values in the dropdown ("Group"). The problem is that the tableOutput only shows the data from just one chosen value from the dropdown. However, I would like to see all the values that are chosen from the dropdown. For instance, If a user selects Groups A and B, it will show 3 rows (there are 2 rows for Group A and 1 row for Group B). How would one do this?

Any advice would be helpful!

Here is a reproducible code:

library(dplyr)
library(shiny)
library(shinyWidgets)

df <- data.frame("Group" = c("A", "A", "B", "C"), "Number" = c(1, 2, 3, 4))

ui <- fluidPage(
  fluidRow(
    column(4, 
           pickerInput("groupInput", "Group:",
             choices = unique(df$Group),
             multiple = T)
           )
  ),
  mainPanel(
    tableOutput("wholeData")
  )
)

server <- function(input, output, session) {
  data <- reactive({
    req(input$groupInput)
    df %>% 
      filter(Group == input$groupInput)
  })
  
  output$wholeData <- renderTable({
    dataset <- data()
    req(dataset)
  })
}

shinyApp(ui, server)
0 Answers
Related