我希望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)
答案 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)