将数据从 rhandsontable 对象转换为 Shiny 中的数据框

Convert data from rhandsontable object into dataframe in Shiny

我有一个 rHandsontable table (rhandsontable package),现在我正在寻找一种方法来传输数据table 到数据帧中。
到目前为止,我还没有找到如何执行此操作的明确线索。
我将非常感谢简单明了的示例或有用的 link.

此外,我扫描了一个有用的link。它让我们瞥见了如何在 rhandsontable 对象中操作数据。

但是没有找到关于使用方法的说明。它看起来像一个黑盒测试。如果您能分享一些这方面的知识(如果有的话),那就太好了。

查看 shinysky package,因为它使用 Handsontable,它具有 hot.to.df 功能,可让您将数据表转换为 dataframe .下面是一个显示我的意思的最小示例

rm(list = ls())
library(shiny)
library(shinysky)

server <- shinyServer(function(input, output, session) {

  # Initiate your table
  previous <- reactive({head(mtcars)})

  Trigger_orders <- reactive({
    if(is.null(input$hotable1)){return(previous())}
    else if(!identical(previous(),input$hotable1)){
      # hot.to.df function will convert your updated table into the dataframe
      as.data.frame(hot.to.df(input$hotable1))
    }
  })
  output$hotable1 <- renderHotable({Trigger_orders()}, readOnly = F)
  # You can see the changes you made
  output$tbl = DT::renderDataTable(Trigger_orders())
})

ui <- basicPage(mainPanel(column(6,hotable("hotable1")),column(6,DT::dataTableOutput('tbl'))))
shinyApp(ui, server)

嗯,我找到了在 R 中将 rhandsontable 对象转换为 dataframe 的方法。

用函数'hot_to_r'貌似很容易,但是整体的功能描述很差

所以在 CRAN 上的 package description (pdf) 之外查找一些示例和解释。就我而言,我使用了黑盒测试。

这是我的案例:

test_case <- hot_to_r(input$all_updates)

变量'test_case'是一个数据帧。

我在这里创建了一个可重现的示例,用于我现有的闪亮应用程序:

library(shiny)
library(rhandsontable)

server <- shinyServer(function(input, output, session) {
  
  # 1. I assign mtcar df to my rhandsontable ("test_table")
  output$test_table <- renderRHandsontable({
    rhandsontable(mtcars)
  })
  
  # 2. I can make some changes to this rhandsontable and generate the resulting table as dataframe
  values <- reactiveValues(data = NULL)
  
  observe({
    values$data <- hot_to_r(input$test_table)
  })

  # 3. I assign this df to a variable call df1
  df1 <- reactive({
    values$data
  })
  
  # 4. Click on action button to see df
  observeEvent(input$print_df_btn, {
    print(df1())
  })
  
})

ui <- basicPage(
  mainPanel(
    rHandsontableOutput("test_table"),
    br(),
    actionButton("print_df_btn", "Print dataframe to console")
    )
  )

shinyApp(ui, server)