As the title suggests, I wish to make a dynamically created UI object (using renderUI) which can be further manipulated later in the Shiny App.
In the below reprex, I have a toy application which allows a user to filter the iris dataset based on the sepal width. Depending on the range the user selects, I then generate a checkbox list of all the unique species within that sepal width range.
My question is: how can I make the app tell me which species' checkbox has been selected once the user has filtered the table? For example, at the default app settings when the sepal width range is between 1 and 2, only one species is satisfies the filter requirement (versicolor). When a user checks the versicolor box, I would like the app to update to tell me that versicolor has been selected.
Similarly, when the sepal width range is greater (and more species are then included in the dynamically generated checkbox list) I would like the UI to update again to tell me which species was selected (either 1, 2 or all 3 species).
The basic workflow in my head is:
(1) User filters Dataset (2) Displayed Table Updates Based on Filter (3) App Generates Checkbox List of Unique Species (4) User Clicks on Species, Species Name is Presented on-screen.
library(shiny)
library(DT)
library(dplyr)
ui <- basicPage(
fluidRow(
uiOutput("ui"),
sliderInput("slider", "Sepal Width", min = 0, max=20, value=c(1:2)),
tableOutput("data")
),
)
server <- function(input, output){
data("iris")
filtered<-reactive({
iris %>% filter(`Sepal.Width` %in% input$slider[1]:input$slider[2])
})
output$data<-renderTable({
filtered()
})
output$ui<-renderUI({
species<-filtered()
checkboxGroupInput(inputId = 'occurence_checkboxes', label = 'Species', choices = unique(species$Species))
})
}
shinyApp(ui, server)