If there is a more egelant/powerfull approach to be found, id be happy to explore the ideas with you.
I think we are up to this proposal:
AppModel <- function() {
self <- reactiveValues(
name = NULL
)
return(self)
}
AppModel_checkCompleteness <- function(self) {
incomplete <- list(
name = NULL,
completed = TRUE
)
if (is.null(self$name) || stringr::str_length(stringr::str_trim(self$name)) == 0) {
incomplete$name <- "You have not specified your name"
incomplete$completed <- FALSE
}
return(incomplete)
}
ui <- function() {
view <- wellPanel(
style = "width: 70%; margin-left: auto; margin-right: auto",
textInput(
"nameText",
"Your name and surname",
placeholder = "Please write your name and surname"
),
textInput(
"simulatesaved",
"simulatesaved",
value = "john Smith"
),
actionButton("restore_from_saved", "restore from saved"),
textOutput("model_content"),
uiOutput("checklistUi"),
)
return(view)
}
server <- function(input, output, session) {
app_model <- AppModel()
.generateChecklistUi <- function() {
Sys.sleep(2)
completed <- AppModel_checkCompleteness(app_model)
if (completed$completed) {
completion_widget <- paste0("model content: ", app_model$name)
} else {
completion_widget <- "model content: not valid"
}
return(completion_widget)
}
observeEvent(input$nameText, {
app_model$name <- req(input$nameText)
})
observeEvent(input$restore_from_saved, {
app_model$name <- input$simulatesaved
updateTextInput(
session = session,
inputId = "nameText",
value = app_model$name
)
})
observeEvent(
{
completeness <- AppModel_checkCompleteness(app_model)
return(completeness$completed)
},
{
output$checklistUi <- renderUI(.generateChecklistUi())
}
)
output$model_content <- renderPrint(app_model$name)
}
shinyApp(ui = ui, server = server)
but you had a concern about volume of code to push changes to individual UI widgets