使用闪亮的 Rhandsontable 下载表格

问题描述

我使用 R 中的 Rhandsontable 包创建了一个闪亮的表。我可以使用下面的代码下载 csv 中的表,但是,我希望以这样一种方式创建一个功能,即输入验证和复选框保留用户也可以在下载的文件中使用。可以在闪亮的情况下做到这一点吗?

library(rhandsontable)
library(shiny)

ui <- fluidPage(
  titlePanel("Handsontable"),sidebarLayout(
    sidebarPanel(
      helpText("Handsontable demo output. Column add/delete does work ","for tables with defined column properties,including type."),radioButtons("useType","Use Data Types",c("TRUE","FALSE"))
    ),mainPanel(
      rHandsontableOutput("hot",width = 350),actionButton("savefile","Save",width = '100%')
    )
  )
)

server <- function(input,output,session) {
  # this caching step is no longer necessary
  # it was left as an example
  values = reactiveValues()
  
  data = reactive({
    if (!is.null(input$hot)) {
      DF = hot_to_r(input$hot)
    } else {
      if (is.null(values[["DF"]]))
        DF = data.frame(val = 1:10,bool = TRUE,big = LETTERS[1:10],small = letters[1:10],stringsAsFactors = F)
      else
        DF = values[["DF"]]
    }
    
    values[["DF"]] = DF
    DF
  })
  
  output$hot <- renderRHandsontable({
    DF = data()
    if (!is.null(DF))
      rhandsontable(DF,useTypes = as.logical(input$useType),stretchH = "all") %>%
      hot_col(col = "big",type = "dropdown",source = LETTERS) %>%
      hot_col(col = "small",type = "autocomplete",source = letters,strict = FALSE)
  })
  
  observeEvent(input$savefile,{
                 if (!is.null(isolate(input$hot)))
                 {
                   #Convert to R object
                   x <- hot_to_r(isolate(input$hot))
                   write.csv(x,file = '~/employee_input.csv',row.names=FALSE)
                 }
               }
  )
}

shinyApp(ui,server)

Please change the directory in "write.csv" in case the downloaded file is not located.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)