Hi,
The reason it's not working is because the data should be in a reactive format, so different Shiny functions can access it, but you must also prevent it from triggering an update when it changes by isolating it in the render function. This way the table on the screen will only update when any of the buttons is pressed because they activate the render function (input triggers are inside function).
There are other ways to clean this up, but I tried to keep most of your original structure:
library(shiny)
library(DT)
ui <- fluidPage(
titlePanel("Test DT"),
sidebarLayout(
sidebarPanel(
numericInput("chooseNumber1", "Choose value to add", value = 2),
actionButton('refresh', 'Refresh Table'),
actionButton('modal', 'Show modal')
),
mainPanel(
DT::dataTableOutput('table')
)
)
)
server <- function(input, output) {
myData = reactiveVal(iris)
observeEvent(input$modal, {
showModal(modalDialog('Simple modal dialog.', numericInput("chooseNumber2", "Choose value to multiply", value = 2),
footer= list(actionButton('refresh2', 'Refresh too'), modalButton("Dismiss")), easyClose = T))
})
observeEvent(input$refresh, {
myData(myData()[,1:4] + input$chooseNumber1)
})
observeEvent(input$refresh2, {
removeModal()
myData(myData()[,1:4] * input$chooseNumber2)
})
output$table <- DT::renderDataTable({
input$refresh
input$refresh2
DT::datatable(isolate(myData()))
})
}
shinyApp(ui = ui, server = server)
Let me kow what you think,
PJ