闪亮无法将上传文件保存在本地磁盘中

时间:2018-08-06 04:07:19

标签: r shiny

我希望Shiny上载并将数据保存在本地磁盘中,除了保存部分之外,其他一切都正常,下面是代码,对您有帮助吗? PS:没有错误消息。

library(shiny)
library(tidyverse)
library(DT)
responsesDir <- file.path("c:/Users/Administrator/Desktop/11") #save at this dir
ui = fluidPage(
  fileInput("FileInput", "File select"),
  DT::dataTableOutput("table")
)

server = function(input, output, session) {
  datasetInput <- eventReactive(input$FileInput, {
    infile <- input$FileInput
    read.csv(infile$datapath, header = TRUE)
  })

  data_save <- eventReactive(
    input$FileInput,
    {write.csv(datasetInput(), file = paste0(responsesDir, '/iris_set.csv'),
               row.names = FALSE, quote = TRUE)}) #name iris_set.csv for example

  output$table = DT::renderDataTable(datasetInput())

}

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

最后一个小时的搜索后,我自己弄清楚了。将eventReactive从data_save行替换为observeEvent即可。

library(shiny)
library(tidyverse)
library(DT)
responsesDir <- file.path("c:/Users/Vincent/Desktop/ls") #save at this dir
ui = fluidPage(
  fileInput("FileInput", "File select"),
  DT::dataTableOutput("table")
)

server = function(input, output, session) {
  datasetInput <- eventReactive(input$FileInput, {
    infile <- input$FileInput
    read.csv(infile$datapath, header = TRUE)
  })

  data_save <- observeEvent(
    input$FileInput,
    {write.csv(datasetInput(), file = paste0(responsesDir, '/fuck_you.csv'),
               row.names = FALSE, quote = TRUE)}) #name iris_set.csv for example

  output$table = DT::renderDataTable(datasetInput())

}

shinyApp(ui, server)