我有一个 Shiny 应用程序,它在 .csv 文件中产生读取并产生一个可编辑的表。
library(dplyr)
library(rhandsontable)
options(shiny.maxRequestSize = 9*1024^2)
function(input, output) {
values <- reactiveValues()
Post <- c("Bank", "Bank")
list2 <- c(12,13)
df <- data.frame(Post, list2)
Post <- c("Ba", "Ba")
list2 <- c(12,13)
df2 <- data.frame(Post, list2)
performTextMining <- reactive({
df$Post <- as.character(df$Post)
df <- df %>% filter(Post == "Bank")
return(df)
})
output$contents <- renderRHandsontable({
items <- c("Boodschappen", "Noodzakelijk")
inFile <- input$file1
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath, header = input$header,
sep = input$sep, quote = input$quote)
#performTextMining()
rhandsontable(df, width = 550, height = 300) %>%
hot_col(col = "Post", type = "dropdown", source = items)
})
filterData <- function(){
setwd("C:/Users/Marc/Dropbox/PROJECTEN/Lopend/visualistation_training/shiny_examples")
write.csv(df, file = "MyData.csv")
}
saveData <- function(){
finalDF <- isolate(values[["df"]])
setwd("C:/Users/Marc/Dropbox/PROJECTEN/Lopend/visualistation_training/shiny_examples")
write.csv(finalDF, file = "MyData.csv")
}
observeEvent(input$saveBtn, saveData())
observeEvent(input$writeBtn, filterData())
}
然而,我想做的是使用保存按钮来存储在表中所做的编辑,然后编写一个 .csv 文件。
因此,我创建了一个保存按钮:
observeEvent(input$writeBtn, filterData())
这会触发以下功能:
saveData <- function(){
finalDF <- isolate(values[["df"]])
setwd("C:/Users/Marc/Dropbox/PROJECTEN/Lopend/visualistation_training/shiny_examples")
write.csv(finalDF, file = "MyData.csv")
}
然而,这给我留下了一个空的 .csv 文件。关于这里出了什么问题的任何想法?