Re: How to reset a value of fileInput in Shiny?

Viewed 274

I would like to revisit the below question:

How can I set the value of a "fileinput" object to NULL, after pressing a reset button?

There are similar posts (how can I update a shiny fileInput object?) and (How to reset a value of fileInput in Shiny?), but as far as I can see the matter has never been resolved.

One comment says: " Earlier this week I submitted a PR to shiny that does some work for this. I think it will be in shiny by the end of the month. – DeanAttali Jun 8 '17 at 6:31

Is there any progress on this front?

1 Answers

I found this to work well. So I'm not resetting the input$fileInput to NULL but I am setting a custom output to NULL, which you can then use for conditionalPanel, toggleState, etc.

UI function

fileInput(...)
conditionalPanel(condition = "output.file_upload_condition", ...)

Server function

values <- reactiveValues(
  upload_state = NULL
)
#
observeEvent(input$loan_agreement_form, {
  values$upload_state <- 'uploaded'
})
#
observeEvent(input$submit_loan, {
  values$upload_state <- 'reset'
})
#
output$file_upload_condition <- reactive({
  if (is.null(values$upload_state)) {
    return(NULL)
  } else if (values$upload_state == 'uploaded') {
    return(input$loan_agreement_form)
  } else if (values$upload_state == 'reset') {
    return(NULL)
  }
})
#
outputOptions(output, "file_upload_condition", suspendWhenHidden = = FALSE)
Related