Shiny Interdependent Filters values - r

Unable to make the similar functionality of filters which should be interdependent. So that means if user select a input from one filter, all other filters should get updated.
I have tried multiple ways in shiny but unable to do so however found some code on stackoverflow with similar functionality. The only challenge is that i don't want to show the table as a output and unfortunately the code does not work if we don't pass the output to #tableprint [id of a table].
Any help would be really appreciated.
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)) ),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
output$tableprint <- DT::renderDataTable({
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
}
# Run the application
shinyApp(ui = ui, server = server)

You can do something like this: its a lot cleaner and easier to read. Note that I added the shinyWidgets package which has the pre-built Select-All Button. You can use the variable called v$df in your other reactives as you said I dont want to show the table as output
library(shiny)
library(dplyr)
library(DT)
library(shinyWidgets)
# Install shinyWidgets
# From CRAN
#install.packages("shinyWidgets")
# From Github
# install.packages("devtools")
#devtools::install_github("dreamRs/shinyWidgets")
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),letters = paste(LETTERS, Numbers, sep = ""))
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
pickerInput("filter1", "Filter 1", choices = LETTERS, options = list(`actions-box` = T), multiple = T),
pickerInput("filter2", "Filter 2", choices = df$Numbers, options = list(`actions-box` = T), multiple = T),
pickerInput("filter3", "Filter 3", choices = letters, options = list(`actions-box` = T), multiple = T)),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
v <- reactiveValues()
observe({
dt <- df$Numbers[df$LETTERS %in% input$filter1]
updatePickerInput(session, "filter2", choices = dt,selected = dt)
})
observe({
dt <- df$letters[df$Numbers %in% input$filter2]
updatePickerInput(session, "filter3", choices = dt,selected = dt)
})
output$tableprint <- DT::renderDataTable({
df <- df[df$LETTERS %in% input$filter1,]
df <- df[df$Numbers %in% input$filter2,]
df <- df[df$letters %in% input$filter3,]
v$df <- df
datatable(df)
})
}
# Run the application
shinyApp(ui = ui, server = server)

Related

How to set up actionButton() or actionBttn() to clear all selections in pickerInput()

When I click on the Action Button, I would like to clear everything: both the output and the selections in the picketInput() (input$engine and input$cylinder in the code below). For consistency if I can do it with shinyWidget's actionBttn, that will be great as well.
library(shiny)
library(shinyWidgets)
df <- mtcars
ui <- fluidPage(
sidebarPanel(
pickerInput("engine", "Select engine:", choices = unique(df$vs),
options = list(
`actions-box` = TRUE),
multiple = TRUE
),
pickerInput("cylinder", "Select cylinder:", choices = unique(df$cyl),
options = list(
`actions-box` = TRUE),
multiple = TRUE
),
actionButton("reset", "Clear Selection"),
),
mainPanel(
textOutput("results")
)
)
server <- function(input, output, session) {
data <- reactiveValues()
observeEvent(input$cylinder, {
tmp <- df
tmp1 <- tmp[tmp$vs %in% input$engine, ]
tmp2 <- tmp1[tmp1$cyl %in% input$cylinder, ]
data$tmp2 <- tmp2
})
output$results <- renderText({
if(is.null(data$tmp2)) return()
print(row.names(data$tmp2))
})
observeEvent(input$reset, {
updatePickerInput(session, "engine", NULL)
updatePickerInput(session, "cylinder", NULL)
data$tmp2 <- NULL
})
}
shinyApp(ui = ui, server = server)
You'll have to respect the order of updatePickerInput's parameters or name them. Your above approach would have updated the label.
Please see ?updatePickerInput and check the following:
library(shiny)
library(shinyWidgets)
library(datasets)
DF <- mtcars
ui <- fluidPage(
sidebarPanel(
pickerInput("engine", "Select engine:", choices = unique(DF$vs),
options = list(
`actions-box` = TRUE),
multiple = TRUE
),
pickerInput("cylinder", "Select cylinder:", choices = unique(DF$cyl),
options = list(
`actions-box` = TRUE),
multiple = TRUE
),
actionBttn("reset", "Clear Selection"),
),
mainPanel(
textOutput("results")
)
)
server <- function(input, output, session) {
data <- reactiveValues()
observeEvent(input$cylinder, {
tmp <- DF
tmp1 <- tmp[tmp$vs %in% input$engine, ]
tmp2 <- tmp1[tmp1$cyl %in% input$cylinder, ]
data$tmp2 <- tmp2
})
output$results <- renderText({
req(data$tmp2)
row.names(data$tmp2)
})
observeEvent(input$reset, {
updatePickerInput(session, inputId = "engine", selected = "")
updatePickerInput(session, inputId = "cylinder", selected = "")
data$tmp2 <- NULL
})
}
shinyApp(ui = ui, server = server)

Update Select Input Reactive Triggers Twice in R Shiny

I would like to update the options for the select input when someone chooses to filter for the cylinders. However, whenever I update the options in the select input by filtering for cylinders, the reactive fires two times. How can I avoid that?
library(tidyverse)
library(shiny)
library(DT)
data("mtcars")
mtcars <- mtcars %>% tibble::rownames_to_column(var = "cars")
ui <- fluidPage(
shiny::selectInput(
inputId = "cars",
label = "Cars",
choices = mtcars$cars,
selected = mtcars$cars,
multiple = TRUE
),
shiny::checkboxGroupInput(
inputId = "cyl",
label = "Cyl",
choices = unique(mtcars$cyl),
selected = unique(mtcars$cyl)
),
DT::dataTableOutput(outputId = "table")
)
server <- function(session, input, output) {
temp <- shiny::reactive({
temp <- mtcars %>%
dplyr::filter(cars %in% input$cars, cyl %in% input$cyl)
print("Reactive fires twice")
return(temp)
})
shiny::observeEvent(input$cyl, {
shiny::updateSelectInput(
session,
inputId = "cars",
choices = temp()$cars,
selected = temp()$cars
)
})
output$table <- DT::renderDataTable({
temp()
})
}
This solution uses reactive values and I believe avoids the double trigger as it separates trigger events.
library(tidyverse)
library(shiny)
library(DT)
data("mtcars")
mtcars <- mtcars %>% rownames_to_column(var = "cars")
ui <- fluidPage(
selectInput(
inputId = "cars",
label = "Cars",
choices = mtcars$cars,
selected = mtcars$cars,
multiple = TRUE
),
checkboxGroupInput(
inputId = "cyl",
label = "Cyl",
choices = unique(mtcars$cyl),
selected = unique(mtcars$cyl)
),
dataTableOutput(outputId = "table")
)
server <- function(session, input, output) {
r <- reactiveValues(
temp = mtcars
)
observeEvent(input$cyl, ignoreNULL = FALSE, {
r$temp <- mtcars %>%
filter(cyl %in% input$cyl)
updateSelectInput(session,"cars",choices = r$temp$cars, selected = r$temp$cars)
print(input$cyl)
})
observeEvent(input$cars, ignoreNULL = FALSE, {
r$temp <- mtcars %>%
filter(cars %in% input$cars)
})
output$table <- DT::renderDataTable({
r$temp
})
}
shinyApp(ui,server)
Here is a solution using a reactive value instead of a reactive conductor, a priority level for the observers, and freezeReactiveValue:
library(shiny)
library(DT)
data("mtcars")
mtcars <- mtcars %>% tibble::rownames_to_column(var = "cars")
ui <- fluidPage(
selectInput(
inputId = "cars",
label = "Cars",
choices = mtcars[["cars"]],
selected = mtcars[["cars"]],
multiple = TRUE
),
checkboxGroupInput(
inputId = "cyl",
label = "Cyl",
choices = unique(mtcars[["cyl"]]),
selected = unique(mtcars[["cyl"]])
),
DTOutput(outputId = "table")
)
server <- function(session, input, output) {
Temp <- reactiveVal()
observeEvent(list(input[["cars"]], input[["cyl"]]), {
temp <- mtcars %>%
dplyr::filter(cars %in% input[["cars"]], cyl %in% input[["cyl"]])
Temp(temp)
}, priority = 2) # higher priority than the other observer
observeEvent(input[["cyl"]], {
freezeReactiveValue(input, "cars") # prevents the above observer to trigger
updateSelectInput(
session,
inputId = "cars",
choices = mtcars[["cars"]], # don't use Temp() here, otherwise you can't select the removed items
selected = Temp()[["cars"]]
)
}, priority = 1)
output[["table"]] <- renderDT({
Temp()
})
}
shinyApp(ui, server)

Reactive unputs with actionbutton in shiny

I want to have an ractive shiny app with an actionbuttion, ie I want to automaticly show the choice dependeing in each last choice.
For example if I choose "A" in the filter 1 I want to show "1", "27" and "All" choice in filter 2 without actionate the "go" button
Here is my code :
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)),
actionButton("go_button", "GO !")),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
goButton <- eventReactive(input$go_button,{
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
output$tableprint <- DT::renderDataTable({
goButton()
})
}
# Run the application
shinyApp(ui = ui, server = server)
I have modified your code so that the select input and table is reactive and gets updated when you change any select input.
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = FALSE, choices = c("All", LETTERS), selected = "All"),
selectInput("filter2", "Filter 2", multiple = FALSE, choices = c("All", as.character(seq.int(1, length(letters), 1))), selected = "All"),
selectInput("filter3", "Filter 3", multiple = FALSE, choices = c("All", letters), selected = "All"),
actionButton("go_button", "GO !")),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
server <- function(input, output, session) {
data1 <- reactive({
if("All" %in% input$filter1){
df1 <- df
}else{
df1 <- df[which(df$LETTERS %in% input$filter1),]
}
df1
})
data2 <- reactive({
if("All" %in% input$filter2){
df1 <- data1()
} else if (length(input$filter2)){
df1 <- data1()[which(data1()$Numbers %in% input$filter2),]
}
df1
})
data3<- reactive({
if("All" %in% input$filter3){
df1 <- data2()
} else if (length(input$filter3)){
df1 <- data2()[which(data2()$letters %in% input$filter3),]
}
df1
})
observeEvent(input$filter1,{
updateSelectInput(session, "filter2", choices = c("All", data1()$Numbers), selected = "All")
})
observeEvent(input$filter2,{
updateSelectInput(session, "filter3", choices = c("All", data2()$letters), selected = "All")
})
output$tableprint <- DT::renderDataTable({
data3()
})
}
shinyApp(ui = ui, server = server)
To render the table only button click you can use the following server code instead of the above:
server <- function(input, output, session) {
data1 <- reactive({
if("All" %in% input$filter1){
df1 <- df
}else{
df1 <- df[which(df$LETTERS %in% input$filter1),]
}
df1
})
data2 <- reactive({
if("All" %in% input$filter2){
df1 <- data1()
} else if (length(input$filter2)){
df1 <- data1()[which(data1()$Numbers %in% input$filter2),]
}
df1
})
data3<- reactive({
if("All" %in% input$filter3){
df1 <- data2()
} else if (length(input$filter3)){
df1 <- data2()[which(data2()$letters %in% input$filter3),]
}
df1
})
observeEvent(input$filter1,{
updateSelectInput(session, "filter2", choices = c("All", data1()$Numbers), selected = "All")
})
observeEvent(input$filter2,{
updateSelectInput(session, "filter3", choices = c("All", data2()$letters), selected = "All")
})
observeEvent(input$go_button,{
output$tableprint <- DT::renderDataTable({
data3()
})
})
}
In the above code you will notice that after it renders for the first time it gets updated automatically when we change the value of selectinput. To avoid that and get the new table rendered only in the end the code below can be used:
server <- function(input, output, session) {
data3<-NULL
data1 <- reactive({
if("All" %in% input$filter1){
df1 <- df
}else{
df1 <- df[which(df$LETTERS %in% input$filter1),]
}
df1
})
data2 <- reactive({
if("All" %in% input$filter2){
df1 <- data1()
} else if (length(input$filter2)){
df1 <- data1()[which(data1()$Numbers %in% input$filter2),]
}
df1
})
observeEvent(input$filter1,{
updateSelectInput(session, "filter2", choices = c("All", data1()$Numbers), selected = "All")
})
observeEvent(input$filter2,{
updateSelectInput(session, "filter3", choices = c("All", data2()$letters), selected = "All")
if("All" %in% input$filter3){
data3 <<- data2()
} else if (length(input$filter3)){
data3 <<- data2()[which(data2()$letters %in% input$filter3),]
}
})
observeEvent(input$go_button,{
output$tableprint <- DT::renderDataTable({
data3
})
})
}
Hope it helps!

Use actionButton with updateSelectInput in a shiny app

I Have a shiny app that use UpdateselectInput, I want to add a actionButton because there are some bugs whis the updateselectInput alone.
It doesnt seem to work, I want to show the table only if I action the button
My app is similar to this one :
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)),
actionButton("go_button", "GO !")),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
output$tableprint <- DT::renderDataTable({
input$go_button
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thanks for help !
Are you looking for something like this?? Only when you click on the Go button, will the table display now. The way the filters work are just the same.
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)),
actionButton("go_button", "GO !")),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
goButton <- eventReactive(input$go_button,{
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
output$tableprint <- DT::renderDataTable({
goButton()
})
}
# Run the application
shinyApp(ui = ui, server = server)
I have moved the filter code to a eventReactive function. So when you click on the button, it will subset your data based on the filters. And the output$tableprint function calls this reactive function, so you will see the table only when you click on the button.

Shiny filter update doesnt show all modalities of variables

i'm trying yo built a dynamic app with can filter a datatable, whatr I want is when I choose a modality for my first varible my next filters will be updated and purpose me only modalities corresponding to my first filter and the same for the third filter
I began by a reactive app but it not seems to works cause i have to always keep the "all" choice to show the other modalities and remove it after that ...is it possible to do that ?
So I decided to add an action button but not seems to work well with my update inputs
How can i fix it ? Thanks
An example of my app :
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = T, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = T, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = T, choices = c("All", letters)),
actionButton("goButton", "Go!"),
p(class = 'text-center', downloadButton('dl', 'Download Data'))
),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
output$tableprint <- DT::renderDataTable({
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
input$goButton
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
datatable(df1)
})
output$dl <- downloadHandler('mydata.csv', content = function(file) {
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
datatable(df1)
write.csv(df1, file)
})
}
# Run the application
shinyApp(ui = ui, server = server)
When I select A and B in Filter1, the dataset is subset for LETTERS with A and B. The options in Filter2 are 1,2,27,28 and Filter3 are A1, B2, A27, B28. When I select 1 in Filter2, the option in Filter3is A1 and when 2 is also selected in Filter2, Filter3 is updated with A1 and A27 as options. You do not have an All option for Filter2 and Filter3. Is this what you are expecting?
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)) ),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
output$tableprint <- DT::renderDataTable({
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
}
# Run the application
shinyApp(ui = ui, server = server)
This code does not include the action button.

Resources