Created
March 20, 2017 16:45
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this is helpful, but is there any way to print the table if the data are uploaded again after reset?