Skip to content

Instantly share code, notes, and snippets.

@bborgesr
Created March 20, 2017 16:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bborgesr/07406b30ade8a011e59971835bf6c6f7 to your computer and use it in GitHub Desktop.
Save bborgesr/07406b30ade8a011e59971835bf6c6f7 to your computer and use it in GitHub Desktop.
How to "reset" a fileInput widget and the underlying data (must treat these as two different things)
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
fileInput('inFile', 'Choose file'),
actionButton('reset', 'Reset'),
tableOutput('tbl')
)
server <- function(input, output, session) {
rv <- reactiveValues(data = NULL)
observe({
req(input$inFile)
rv$data <- read.csv(input$inFile$datapath)
})
observeEvent(input$reset, {
rv$data <- NULL
reset('inFile')
})
output$tbl <- renderTable({
rv$data
})
}
shinyApp(ui, server)
@fawda123
Copy link

Thanks this is helpful, but is there any way to print the table if the data are uploaded again after reset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment