R shiny: make fileInput widget disappears after file input
1 answer
Hi StΓ©phane Laurent answered a similar question in this post , with a minimal example:
data("kyphosis", package = "rpart")
write.table(kyphosis, file = "kyphosis.txt", row.names = FALSE)
library(shiny)
runApp(list(
ui = pageWithSidebar(
headerPanel = headerPanel(" "),
sidebarPanel = sidebarPanel( conditionalPanel(condition = "output.fileUploaded",
fileInput(inputId = "file_input", label = "Input" ) )),
mainPanel = mainPanel( tableOutput(outputId = "table"))
),
server = function(input, output) {
getData <- reactive({
if(is.null(input$file_input)) {
return(NULL)
} else {
return(read.table(input$file_input$datapath, header = TRUE))
}
})
output$fileUploaded <- reactive({
return(is.null(getData()))
})
output$table <- renderTable({
head(getData())
})
outputOptions(output, 'fileUploaded', suspendWhenHidden=FALSE)
}
))
+3
source to share