I’m trying to build a Shiny App to present some model simulations. The user should have the possibility to update all input variables to his own values.
The App has several tabs: first the simulation results and second the input data table. As long as nothing is changed on the inputs data table, the simulation should run with the original values.
The problem is that the calculation in the fist tab es not executed until clicking once on the second tab with the input data table.
I found out that it works fine if the input table is the first tab, but that is not what i want to have.
Here is a small example app showing the problem:
library(shiny)
library(datamods)
library(reactable)
#Create test dataframe
aa<-c("A","B","C","D")
bb<-c(1:4)
test_df<-data.frame(aa,bb)
#App####
#UI####
ui <- fluidPage(
navbarPage(title = "Test",
header=tags$head(tags$style(type='text/css', ".irs-grid-text { font-size: 10pt; }")),
tabPanel(title = "Example",
mainPanel(
verbatimTextOutput("test_data")#,
)),
tabPanel(title = "Input data",
mainPanel(
edit_data_ui(id = "id")#,
))
)
)
#Server####
server <- function(input, output) {
edited_r <- edit_data_server(
id = "id",
data_r = reactive(test_df),
add = FALSE,
update = TRUE,
delete = FALSE,
file_name_export = "datas",
var_labels = list(
aa = "name",
bb = "value"
),
var_edit=list("bb"),
reactable_options = list(
defaultColDef = colDef(filterable = TRUE),
selection = "single",
columns = list(
bb = colDef(name = "value", style = list(fontWeight = "bold"))),
bordered = TRUE,
compact = TRUE,
searchable = TRUE,
highlight = TRUE
)
)
output$test_data <- renderPrint({
sum(edited_r()$bb)
})
}
# Run the application
shinyApp(ui = ui, server = server)
My goal is that the result (in this example the sum) is directly calculated when the App is started. Currently the user has to click on the second tab and go back to the first to trigger the calculation.
Is there a way to define that the original inputs should be used as long as there are no changes?
Ch_Schmitz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.