For one of my Rshiny app, I am referring to this R shiny code from StackOverflow: In R Shiny, how do you reset data (reversing all manual inputs) in rhandsontable using an actionButton?
When we use the package "rhandsontable," the following code displays the DataTable whenever we click the "show" button. Although the rhandsontable package includes a default context menu, it can be customized using the "hot_context_menu" code.
issue:
The problem is with the 'undo' option in the context menu (right-click on the data table). The option 'undo' enabled to work only when we adjust alignment (right-click on the data table), but not (disabled) when we remove a row (Remove row), "insert row below," and so on.
Could someone help me to fix this issue?
original code
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)))
observeEvent(input$hot, {
dat(as.data.frame(hot_to_r(input$hot)))
})
observeEvent(input$show, {
showModal(modalDialog(rHandsontableOutput("hot")))
})
observeEvent(input$reset, {
dat(data.frame(x = runif(5), y = runif(5)))
})
output$hot <- renderRHandsontable({
# input$show
rhandsontable(dat())
})
} # close Server
shinyApp(ui, server)
Edited Code
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)))
observeEvent(input$hot, {
dat(as.data.frame(hot_to_r(input$hot)))
})
observeEvent(input$show, {
showModal(modalDialog(rHandsontableOutput("hot")))
})
observeEvent(input$reset, {
dat(data.frame(x = runif(5), y = runif(5)))
})
output$hot <- renderRHandsontable({
rhandsontable(dat())
})
outputOptions(output, "hot", suspendWhenHidden = FALSE)
} # close Server
shinyApp(ui, server)