I am working on a shiny app where on load it shows a default table. Have a user input which when I enter and click on run should update the table. And also when clicked on reset it should show the default table.As of now I am able to view the default table and nothing happens when I click on the run button.
optimzation <- function(input, output, session, data,budget,run,reset) {
v <- reactiveValues(data = data)
observeEvent(run, {
v$data <- data %>% mutate(carb = mpg * budget)
})
observeEvent(reset, {
v$data <- data # your default data
})
output$mod_table <- DT::renderDataTable({
DT::datatable(v$data, filter = "top")
})
}
optimzationUI <- function(id) {
ns <- NS(id)
dataTableOutput(ns("mod_table"))
}
shinyApp(
ui = basicPage(
mainPanel(
numericInput("budget_input", label = h5("Total Budget"), value = 9000000),
actionButton("opt_run", "Run"),
actionButton("opt_reset", "Reset"),
tags$hr(),
optimzationUI("optimize")
)
),
server = function(input, output) {
demodata<-mtcars
callModule(optimzation,"optimize", demodata,budget=input$budget_input,run=input$opt_run,reset = input$opt_reset)
}
)
Created on 2019-02-13 by the reprex package (v0.2.1.9000)