0

I have a simple shiny app in which I need to upload a csv and then I should be able to reset it by clicking the action button. If there is no file an error message should be displayed. The issue is that this error message is not displayed after clicking the reset button.

library(shiny)
library(shinyjs)
library(tidyverse)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
  useShinyjs(),
  fileInput('inFile', 'Choose 1st file'),
  tags$hr(),
  actionButton('reset', 'Reset')
    ),
  mainPanel(
    textOutput("choose")
  )
)
)

server <- function(input, output, session) {

  rv <- reactiveValues(
    data = NULL,
    clear = FALSE
  )
  ########1st
  observe({
    req(input$inFile)
    req(!rv$clear)

      rv$data <- read.csv(input$inFile$datapath,header = T)



  })

  observeEvent(input$inFile, {
    rv$clear <- FALSE
  }, priority = 1000)

  observeEvent(input$reset, {
    rv$data <- NULL
    rv$clear <- TRUE
    reset('inFile')
  }, priority = 1000)



  output$choose <- reactive({
    if(is.null(input$inFile))
    {
      "You must upload 1st csv at least"
    }
    else
    {
      "Now we can process the data!"
    }
  })
}

shinyApp(ui, server)
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

Just a little typo on line 49.

This line
if(is.null(input$inFile))

should be
if(is.null(rv$data))

Ash
  • 1,463
  • 1
  • 4
  • 7
  • maybe you could help with this one https://stackoverflow.com/questions/61349868/jsoneditoutput-is-not-displayed-when-given-as-reactive-value-in-a-shiny-app – firmo23 Apr 21 '20 at 21:15