0

I have a Shiny Dashboard App that shows simple plot. I´m filtering the dataframe that feeds the plot using 2 different filters.

What I want is, is it possible for the app to have it so that:

  1. I select a value in filter 1
  2. If I now filter for a value on filter 2, then filter 1 resets to it's original value
  3. Basically I´m only allowing 1 filter at a time

Thx!

EGM8686
  • 1,492
  • 1
  • 11
  • 22
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 06 '20 at 21:25

1 Answers1

1

You want to use updateSelectInput and then use observeEvent to catch when a filter value changes.

library(shiny)
library(shinydashboard) 

rm(list=ls())

#####/UI/####

header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
  selectInput(inputId = "filter1", label = "Filter 1", selected = "ALL",
              choices = c("ALL", "Bananas", "Apples", "Oranges")
  ),
  selectInput(inputId = "filter2", label = "Filter 2", selected = "ALL",
              choices = c("ALL", "Carrots", "Peas", "Celery")
  )
)

ui <- dashboardPage(header, sidebar, body)

#####/SERVER/####
server <- function(session, input, output) { 

  observeEvent(input$filter2,{
    if (input$filter2 != "ALL") {
      updateSelectInput(session, "filter1", selected = "ALL")
      }
  })

  observeEvent(input$filter1,{
    if (input$filter1 != "ALL") {
      updateSelectInput(session, "filter2", selected = "ALL")
    }
  })

  }

shinyApp(ui, server)
Kevin
  • 1,974
  • 1
  • 19
  • 51