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)