1

I am trying to understand how hot_to_r() convert the list object obtained with rhandsontable(). My goal is to see the object that you get after hot_to_r() processes in order to debug a shiny app.

However, it seems that you can not do this outside the shiny app i.e inside a .R script.

[EDIT] searching further leads me to this post. Are we sure that the object that you get from fromJSON() is the same as the one from hot_to_r()

Here is a .R script I was trying to use to see the output of hot_to_r():

library(rhandsontable)
library(tidyverse)
library(jsonlite)

# dummy dataframe
df = data.frame(id = c("a", "b"),
                val = c(0.75, 0.25))

# convert it to a "rhansontable" object
test = rhandsontable(df)

# try to convert it back to a dataframe but it doesn't work
test_hot = hot_to_r(test)

# however, this works but I am not sure if test_json is the same as test_hot
test_json = fromJSON(test$x$data)

test_hot = hot_to_r(test) leads to this error:

test_df = hot_to_r(test)

Error in (function (data, changes, params, ...) : argument "params" is missing, with no default

I am very new to shiny ; am I missing something?

Is it normal that you can not get hot_to_r() work inside a .R script?

If yes, how do you check the "aspect" of your data inside the shiny app? The overall goal is to make calculations with a rhandsontable filled by users. I want to transform this object into a dataframe in order to make the correct modifications to get a "tidy" dataset.

Community
  • 1
  • 1
Paul
  • 2,850
  • 1
  • 12
  • 37

1 Answers1

2

hot_to_r is intended to be used with a shiny input (which contains the params argument mentioned in the error message).

For debugging in the shiny context I'd recommend using browser().

Please check the following:

library(rhandsontable)
library(shiny)

ui <- fluidPage(
  rHandsontableOutput("myTable")
)

server <- function(input, output, session) {
  # dummy dataframe
  df = data.frame(id = c("a", "b"),
                  val = c(0.75, 0.25), stringsAsFactors = FALSE)

  # convert it to a "rhansontable" object
  output$myTable <- renderRHandsontable({rhandsontable(df)})

  observeEvent(input$myTable, {
    test_df = hot_to_r(input$myTable)
    print(test_df)
    # browser() # uncomment for debugging
  })

}

shinyApp(ui, server)

However, fromJSON also is a valid approach.

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78