R shiny: reloading data with fileInput

对着背影说爱祢 提交于 2020-01-02 12:21:19

问题


Is there a way to reload input file, which was loaded with fileInput? I would like to allow the user to update his input by simple modification and reloading of csv file. It seems like reloading the file does not update it. One workaround, which helps is to save the modified data with different file name.

I've tried already exchanging fileInput function with an actionButton and file.choose(), but it won't work with R server

Here's my test code:

server.R

shinyServer(function(input, output, session) {

getTestOutput <- reactive({
 if(is.null(input$test))
   return(NULL)

isolate({
 writeLines(paste(input$test, collapse = "\n"))
 })
})

getTable <- reactive({
 if( is.null(input$test))
  return(NULL)

 r <- read.csv((input$test)$datapath,sep=";",header = TRUE)
 as.data.frame(r)
})

output$testOutput <- renderPrint({
  getTestOutput()

})

output$testTable <- renderTable({
  if(is.null(getTable())) 
   return(NULL)

  print(getTable())
})
})

ui.R

shinyUI(
 fluidPage(

sidebarPanel(
  fileInput("test","Load a file")
),

mainPanel(
  verbatimTextOutput("testOutput"),
  tableOutput('testTable')
  )
)
)

回答1:


If the Shiny app is on a separate server, then I believe this is fundamentally impossible using a normal web browser; simply saving the data file is not enough, you need to actually perform a new upload after each change.

However, if the Shiny app is being run on the user's machine (i.e. they are running an R session themselves and calling a function that launches Shiny) then you can just ask them for a path and use reactiveFileReader to automatically update the results whenever the file changes.



来源:https://stackoverflow.com/questions/28021237/r-shiny-reloading-data-with-fileinput

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!