我有一个Shiny应用程序,它在.csv文件中生成读取并生成一个可编辑的表。
this.setState({foo: this.state.foo - 1})
我想要做的是使用保存按钮存储在表格中进行的编辑,然后写一个.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())
}
触发以下功能:
observeEvent(input$writeBtn, filterData())
然而,这给我留下了一个空的.csv文件。对这里出了什么问题的想法?
答案 0 :(得分:4)
要从已编辑的hot_to_r()
获取数据,需要调用saveData <- function(){
finalDF <- hot_to_r( input$contents )
write.csv(finalDF, file = "C:/Users/Marc/Dropbox/PROJECTEN/Lopend/visualistation_training/shiny_examples/MyData.csv")
}
函数。在上面的例子中应用它,代码应如下所示:
{{1}}