Following the answers here I tried to use shinyjs to reset input value by giving the id to the div in the UI and calling that in when clicked on reset. Below is my code for what I have tried.
library(shiny)
library(DT)
library(dplyr)
library(shinyjs)
#### Module 1 renders the first table
tableMod <- function(input, output, session, modelRun,reset,modelData,budget){
output$x1 <- DT::renderDataTable({
modelRun()
isolate(
datatable(
modelData %>%
mutate(Current = as.numeric(Current)*(budget())),
selection = 'none', editable = TRUE
)
)
})
observeEvent(reset(), {
shinyjs::reset("input-panel")
})
}
tableUI <- function(id) {
ns <- NS(id)
dataTableOutput(ns("x1"))
}
ui <- function(request) {
fluidPage(
div(shinyjs::useShinyjs(), id = "input-panel",
tableUI("opfun"),
numericInput("budget_input", "Total Forecast", value = 2),
actionButton("opt_run", "Run"),
actionButton("opt_reset", "Reset")
))
}
server <- function(input, output, session) {
df <- data.frame(Channel = c("A", "B","C"),
Current = c(2000, 3000, 4000),
Modified = c(2500, 3500,3000),
New_Membership = c(450, 650,700),
stringsAsFactors = FALSE)
callModule( tableMod,"opfun",
modelRun = reactive(input$opt_run),
reset = reactive(input$opt_reset),
modelData = df,
budget = reactive(input$budget_input))
observeEvent(input$opt_run, {
cat('HJE')
})
}
shinyApp(ui, server, enableBookmarking = "url")