0

How can i clear fileInput backened data file as soon as i change the option for selectinput. I have tried renderUI function but options are large and i have also tried rendering sample id to fileInput but observeevent is not working.

1 Answers1

0

This goes well with using a bit JavaScript. Assuming btn is the id of your selectInput :

server.R

shinyServer(function(input, output, session) {

  observe({
    input$btn
    session$sendCustomMessage(type = "resetFileInputHandler", "file1") 
  })

})

Now, on the client side we need to register a handler function that will be called by the server and perform the necessary changes.

ui.R

shinyUI(bootstrapPage(

  fileInput('file1', 'I am the fileInput'),
  selectInput("btn", "Change me", c(1,2,3)),

  tags$script('
    Shiny.addCustomMessageHandler("resetFileInputHandler", function(x) {      
        var id = "#" + x + "_progress";      # name of progress bar is file1_progress
        var idBar = id + " .bar";  
        $(id).css("visibility", "hidden");   # change visibility
        $(idBar).css("width", "0%");         # reset bar to 0%
    });
  ')
))

source

Levon Ipdjian
  • 786
  • 7
  • 14