In Shiny, how to reset rhandsontable table to default values, reversing all user inputs?

I have been trying to render a super-simple, example editable table using the rhandsontable package within Shiny modal dialog and have run into a snag that I haven't been able to resolve after repeated tries and searches. I am unable to reset the table to it's default configuration of 2 x 2 dimensions, reversing all user inputs, upon the click of a "Reset" action button. Although there is a somewhat analogous post/solution ( Resetting dynamic table with actionButton), that App is more complicated and it's difficult for me to untangle the pure reset function from the rest of the App code.

So my question is: how do I reset the rendered table to default configuration with the click of an action button?

Below is MWE code:

library(shiny)
library(rhandsontable)

ui <- fluidPage(actionButton("show","Show"), 
                actionButton("reset","Reset"))

server <- function(input,output,session){
  
  dat <- reactiveVal(data.frame(x=runif(2),y=runif(2)))
  
  dat1 <- reactive({
    if(is.null(input$hot)){
      dat()
    } else {
      as.data.frame(hot_to_r(input$hot))
    }
  })
  observeEvent(input$show,{showModal(modalDialog(rHandsontableOutput("hot")))})
  
  observeEvent(input$reset,dat(data.frame(x=runif(2),y=runif(2))))
  
  output$hot <- renderRHandsontable(rhandsontable(dat1()))
  
} #

shinyApp(ui,server)

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.