So I'm writing quite a complicated application which resets the value of fileInput and its associated dataframe in a manner like in this post https://groups.google.com/d/msg/shiny-discuss/HbTa4v612FA/AJ-R3WB7BAAJ. To do this I need to use reactiveValues to store the data
I'm having problems with the renderDT function not updating itself if the first fileInput throws an error (I've programmed the server to check the file to see if it's corrupted).
It's all very complicated but I've narrowed down the problem to the use of renderDT. If I use ordinary tables it works as expected. I've made two Shiny apps to illustrate the problem. The first one works fine and the second one doesn't. I'm totally stumped, I can't for the life of me think what the difference is.
Here's one that works (apologies the top of the code will WRITE A CSV FILE TO YOUR WORKING DIRECTORY- this is to give you something to feed into the file input)
library(shiny)
library(DT)
testFrame = data.frame("a" = c(1, 2), "b" = c(3, 4))
write.csv(testFrame, "temp.csv")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file",
"Choose file")
),
mainPanel(
tableOutput("theData")
)
)
)
server <- function(input, output) {
rv <- reactiveValues(data = NULL, message = NULL)
observe({
validate(
need(!is.null(input$file), "Input data")
)
rv$data = read_csv(input$file$datapath)
})
output$theData = renderTable({
rv$data
})
}
# Run the application
shinyApp(ui = ui, server = server)
Whereas this one, which is the same code except using renderDT and DTOutput, does not work at all
library(shiny)
library(DT)
testFrame = data.frame("a" = c(1, 2), "b" = c(3, 4))
write.csv(testFrame, "temp.csv")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file",
"Choose file")
),
mainPanel(
DTOutput("theData")
)
)
)
server <- function(input, output) {
rv <- reactiveValues(data = NULL, message = NULL)
observe({
validate(
need(!is.null(input$file), "Input data")
)
rv$data = read_csv(input$file$datapath)
})
output$theData = renderDT({
rv$data
})
}
# Run the application
shinyApp(ui = ui, server = server)
Help!