Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert data from rhandsontable object into dataframe in Shiny

I have a rHandsontable table (rhandsontable package) and now I am searching a way how to transfer data from the table into a dataframe.
So far I have not found a clear clue how to perfrom this action.
I would be very grateful for the plain and clear example or useful link.

Besides, I have scanned a useful link. It throws a glimpse of light concerning how to manipulate data inside rhandsontable object.

But no explanation about methods used have been found. It looks like a black box testing. It would be nice if you could share some knowledge of this matter (if any).

like image 700
Dimon D. Avatar asked Feb 07 '26 03:02

Dimon D.


1 Answers

Look into the shinysky package, as it uses Handsontable, which has hot.to.df function that would allow you to convert your datatable into dataframe. Below is a minimal example showing what I mean

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)
like image 86
Pork Chop Avatar answered Feb 09 '26 07:02

Pork Chop