In below MWE code, the action button "show" triggers a modal dialogue box with a table the user can manipulate, using rhandsontable. Works as intended, except the "reset" button doesn't work. Reset should reverse all user inputs into the table and bring back a 2 column, 5 row table of random variables.
How do I reset the table? I've been fooling around with this this morning and no luck yet.
This needs to stay in modalDialog by the way! Rhandsontable in a modal dialog box seems tricky but is tremendously functional for this model with many inputs.
See images at the bottom. First image shows what happens when first invoking the App and clicking the "Show" action button. Good - a 5 row, 2 column table appears. Second image is what shows after the user right clicks on the table to insert an additional row at the bottom, entering a 6 into the x and y columns of the 6th row. If you click to "Dismiss" the modal and click "Show" again, good -- the same modified table appears, as intended. Repeatedly clicking Dismiss/Show keeps bringing back the same modified 6 row table -- good! But if you hit "Reset", the modified table with the 6th added row keeps coming back. Should revert to a 5 row table. If the user has manually input many rows into the table and not just one additional row like in this example, reset should bring back a 5 row table.
library(shiny)
library(rhandsontable)
ui <- fluidPage(actionButton("show","Show"),
actionButton("reset","Reset"))
server <- function(input, output, session){
dat <- reactiveVal(data.frame(x=runif(5),y=runif(5)))
dat1 <- reactive({
if(is.null(input$hot)){dat()}
else {as.data.frame(hot_to_r(input$hot))}
}) # close reactive
observeEvent(input$show,{showModal(modalDialog(rHandsontableOutput("hot")))})
observeEvent(input$reset,{dat(data.frame(x=runif(5),y=runif(5)))})
output$hot <- renderRHandsontable(rhandsontable(dat1()))
} # close Server
shinyApp(ui,server)
And below is an image showing the obscured table after making a change to it and hitting the "Show" button (the entire table should be appearing instead):