Friends, I would like you to help me with the following question: The executable code below generates clusters and shows in a table which industries are part of each cluster
You can create a reactive flag (confirmed_status) that will change when you confirm via the sweetalert. It will default to false, and an observeEvent can be triggered by the result of your alert to change to true when confirmed button is pressed. Then, if you don't want to show the dialog box again after confirming, you can check confirmed_status in your observe before displaying it again. Let me know if this is the behavior you were looking for.
server <- function(input, output, session) {
confirmed_status <- reactiveVal(FALSE)
Modelcl<-reactive(function.cl(df,input$Slider))
output$ind <- renderTable({
IND <- ((Modelcl()[[1]]))
})
observe({
if(is_empty(Modelcl()[[1]])==FALSE && isFALSE(confirmed_status())){
confirmSweetAlert(
session = session,
inputId = "myconfirmation",
btn_labels = c("Confirm", "Not yet"),
text = tags$div(h5("The industry below is being excluded from clustering:"),
paste(Modelcl()[[1]], collapse = ", ")),
type="info"
)
}})
observeEvent(input$myconfirmation, {
if (isFALSE(input$myconfirmation)) {
confirmed_status(TRUE)
} else {
# Add here more for the "Not yet" condition
}
})
output$tabela <- renderDataTable({
data_table_1 <- req(Modelcl())[[2]]
x <- datatable(data_table_1[order(data_table_1$cluster), c(1, 4, 2, 3)],
options = list(
paging =TRUE,
pageLength = 5
)
)
return(x)
})
}