'In a dashboard made with R, how can I filter/unfilter based on selectInput?

I have created a simple dashboard (link here) to display some data in R using selectInput. How can I activate/deactivate a filter reactively, so that the output could be not always filtered?

This is the code I am using:

load("censup_lean.RData")
escolhe_cursos <- sqldf("select distinct CURSO from CURSOS_MEDIUM order by CURSO")
selectInput("CURSO", label="Curso:", choices = escolhe_cursos, selected = "Design gráfico")

escolhe_estado_curso <- sqldf("select distinct UF_CURSO from CURSOS_MEDIUM order by UF_CURSO")
selectInput("UF", label="Estado do Curso:", choices = escolhe_estado_curso, selected = "Rio de Janeiro")

escolhe_modalidade_curso <- sqldf("select distinct TP_MODALIDADE_ENSINO from CURSOS_MEDIUM")
selectInput("MODALIDADE", label = "1. Presencial ou 2. EAD", choices = escolhe_modalidade_curso, selected = "1")

renderPlotly({
  g<-filter(CURSOS_MEDIUM, CURSO == input$CURSO, UF_CURSO == input$UF, TP_MODALIDADE_ENSINO == input$MODALIDADE)%>%
    ggplot(., aes(x= ANO, y= INGRESSANTES))+geom_col()+theme_bw()+labs(title = "Ingressantes por Curso, Estado e Modalidade", x="Ano", y="Ingressantes")
  ggplotly(g)
})



Solution 1:[1]

I am also not quie sure what you intend to do but is it related to the updateselcetizeinput functionality? https://shiny.rstudio.com/reference/shiny/0.14/updateSelectInput.html

By using this function, after selecting a certain value in CURSO, The options available in UF will be filtered according to the input in CURSO (if a course is not offered in RDJ, it will not appear once you pick that particular course).

you can also add an eventReactive so your plotly plot will only be generated after the user validates it (press a GO! button for exapmle). More about it here: https://shiny.rstudio.com/reference/shiny/latest/observeEvent.html

df = eventReactive (input$"go",  # wait till this input get validated
{
head(mtcars,input$how_many_to_show) #and then calculate this operation
} )

and now df will be called as a reactive object, df().

I hope it kinda helped.

Solution 2:[2]

I dont know if i understand exactly what you want but try adding this two arguments to your selectInput function and see if thats what you want.

pickerInput("CURSO",
    label="Curso:", 
    choices = escolhe_cursos, 
    selected = "Design gráfico",
    multiple = T,
    options = list(`actions-box` = TRUE))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Gal
Solution 2