Submit button is rendering after pressing clear button

Hi all,

In my below application, all is working well, Once i select filter and Submit, the data is loading good.
I click on clear button, all data is removed.

Problem is again if I press submit button, the data is not loading. Can anyone please help

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(shiny)
library(shinydashboard)
library(shinycssloaders)
library(DT)
library(dplyr)
library(formattable)


```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}


selectInput("Tic","",choices = c("",as.character(iris$Species)),selected = "")
actionButton("Submit","Submit")
actionButton("Clear","Clear")
tableOutput("table")


     data2 <- eventReactive(input$Submit,{
      if(input$Tic != ""){
      iris <- iris %>% filter(Species %in% input$Tic)
      }
        })


output$table <- renderTable({
  data2()
})

      observeEvent(input$Clear,{
      output$table <- renderTable({
  
})
      })
      
```

your issue is that your clear event redefines how table should be rendered away from the initial relationship to 'data2()'
rather than doing that you should make clear change the contents of 'data2 to something like NULL or a frame with no rows.

probably best would be to not make data2 from an evenreactive but from a reactive so it can depend on submit or clear 'reactively' , but you'd want to put input$Tic involved logic inside of isolate({}) so that data2 isnt reactive on Tic

Hi Thanks.

But did not get your logic :frowning:

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---
```{r setup, include=FALSE}
library(shiny)
library(shinydashboard)
library(shinycssloaders)
library(DT)
library(dplyr)
library(formattable)
library(tidyverse)
```{r}
selectInput("Tic", "", choices = c("", as.character(iris$Species)), selected = "")
actionButton("Submit", "Submit")
actionButton("Clear", "Clear")
div(
  style = "height:100px;",
  tableOutput("my_controls")
)
tableOutput("table")

clear_at_submit <- reactiveVal(-1)
submit_at_clear <- reactiveVal(-1)

observeEvent(input$Submit, {
  clear_at_submit(input$Clear)
})

observeEvent(input$Clear, {
  submit_at_clear(input$Submit)
})


my_control_object <- reactive({
  tibble(
    SubmitButton = input$Submit,
    ClearButton = input$Clear,
    clear_at_submit = clear_at_submit(),
    submit_at_clear = submit_at_clear(),
    TicValue = input$Tic,
    `submit_at_clear() != input$Submit?` = submit_at_clear() != input$Submit
  )
})

output$my_controls <- renderTable({
  my_control_object()
})

data2 <- eventReactive(input$Submit, {
  if (input$Tic != "") {
    iris <- iris %>% filter(Species %in% input$Tic)
  }
})

output$table <- renderTable({
  if (submit_at_clear() != input$Submit) {
    data2()
  } else {
    NULL
  }
})

Perfect and thanks a lot

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.