R Shiny: DataTables Warning: Invalid JSON response

I am building a R shiny app. In the app, I have an editable table that allows users to edit numbers. I built this table using R library(DT).

On the server side it looks like this :

Note:

  • On UI side, I ask user to select name(s) of a fruit (one or more from apple, orange, pear, banana)
  • "create_param_table" is a function I wrote that builds a tibble data frame that looks like this (depending on what fruit(s) user picked, for example here users picked apple & orange):
+----------+-----------+-------+-------+
| Category | Parameter | Upper | Lower |
+----------+-----------+-------+-------+
| Apple    | alpha     | 0     | 0     |
+----------+-----------+-------+-------+
| Apple    | beta      | 0     | 0     |
+----------+-----------+-------+-------+
| Orange   | alpha     | 0     | 0     |
+----------+-----------+-------+-------+
| Orange   | beta      | 0     | 0     |
+----------+-----------+-------+-------+
| Orange   | gamma     | 0     | 0     |
+----------+-----------+-------+-------+

param_table <- reactiveValues(df = data.frame())

observeEvent(input$choice, {
    param_table$df <- create_param_table(input$choice)
})

output$param_table <- DT::renderDataTable({
    
      param_table$df %>%
        datatable(
          rownames = FALSE,
          editable = TRUE,
          options = list(
            dom = "t",
            paging = FALSE,
            ordering = FALSE
          )
        ), 
      },server = FALSE)

  param_table_proxy <- dataTableProxy("param_table")

  observeEvent(input$param_table_cell_edit, {
    info <- input$param__table_cell_edit
    i <- as.numeric(info$row)
    j <- as.numeric(info$col) + 1
    v <- as.numeric(info$value)

  param_tables$df[i, j] <<- DT::coerceValue(v, param_table$df[i, j])
  replaceData(param_table_proxy, param_table$df, resetPaging = FALSE) 


  output$my_table <- renderUI({
    req(input$choice) 
     material_card(
        title = tags$b("Parameters"),
        depth = 4,
        DT::dataTableOutput("param_table")
      )
    }
  })

The UI side looks like this:

material_row(
...
...
 material_column(
      width = 3,
      uiOutput("my_table")
)
)
  • I am using this shiny package called "shinymaterial" for my user interface. So the UI construct looks a bit different from traditional bootstrapping Shiny interface.

Here is the problem:

  • The app runs (does not crash), but whenever I edit the number in the datatable, this warning message will show up:
    enter image description here

  • The app still allows me to edit the numbers. But for each number I edit, this warning message shows up. This becomes very cumbersome and very user-unfriendly when I have to edit more than 1 number in the data table.

I am wondering:

  • Is this because the app was expecting the table to be in JSON format, but it is not detecting a JSON table, hence the "invalid JSON response" message?
  • If so, does library(DT) even allows a JSON format table?
  • If not, what could be the source of this error? Could this be something unique about shinymaterial?
  • If there's not an immediate cure, is there anyway I could just force suppress a warning message from popping up in my Shiny app?

Much appreciation for any help & insights into potential solutions!

1 Like

my first thought is that its unwise to reuse object names haphazardly.
param_table is sometimes a reactiveValues, but also a ui output (output$param_table)

My second though is that you nest a lot of reactivity that probably doesnt need to be nested.

You also use a global assignment that is probably more trouble than its worth...

For the best support please consider providing a reprex.
(Shiny debugging and reprex guide)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.