我有一个非常简单的数据框,具有可空泛函。
打开时,空列消失了,并且保存消失了。
这是预期的行为吗?
只需打开此csv,然后在其上使用rhonsontable查看文件即可。
column1,column2,column3
1,,some
2,,thing
3,,disappeared
library(rhandsontable)
library(shiny)
fname <- "data"
values <- list()
setHot <- function(x) values[["hot"]] <<- x
ui <- shinydashboard::dashboardPage(dashboardHeader(title = "Removing columns you wanted?", titleWidth = 990)
dashboardSidebar(disable = TRUE),
dashboardBody(rHandsontableOutput("hot"),
br(),
actionButton("saveBtn", "Save changes")
))
server <- function(input, output, session) {
observe({
input$saveBtn # update csv file each time the button is pressed
if (!is.null(values[["hot"]])) { # if there's a table input
#write.csv(values[["hot"]], fname) # overwrite the temporary database file
write.csv(x = values[["hot"]], file = 'data.csv', row.names = FALSE) # overwrite thecsv
}
})
output$hot <- renderRHandsontable({
if (!is.null(input$hot)) { # if there is an rhot user input...
DF <- hot_to_r(input$hot) # convert rhandsontable data to R object and store in data frame
setHot(DF) # set the rhandsontable values
} else {
DF <- rio::import('data.csv', stringsAsFactors = FALSE)
setHot(DF) # set the rhandsontable values
}
rhandsontable(DF)
}
)
}
shinyApp(ui = ui, server = server)