问题描述
问题:我有以下应用。本质上,我想按下按钮来加载数据。第一次我通过按钮加载数据后,我想询问我是否要保存更改。如果是,则确认更改已成功保存,否则显示其他数据(不包括其他数据)。
方法我试图通过observeEvent
触发的reactiveValues
表达式来解决它。但是,正如您在运行以下脚本时所观察到的那样,此操作无法按预期进行。
问题:对什么地方有误吗?
library(shiny)
library(shinyWidgets)
library(rhandsontable)
shinyApp(
ui = fluidPage(
actionButton("show","Show data",width = "100%"),rHandsontableOutput("data_table")
),server = function(input,output) {
rv <- reactiveValues(
# Triggers
pressed_first_time = 0,confirm_module = TRUE,save_module = TRUE,table_change = TRUE
)
observeEvent(input$show,ignoreInit = TRUE,{
if (rv$pressed_first_time == 0){
rv$pressed_first_time <- isolate(rv$pressed_first_time + 1)
rv$table_change <- isolate(!rv$table_change)
cat("pressed_first time")
} else {
rv$pressed_first_time <- isolate(rv$pressed_first_time + 1)
rv$confirm_module <- isolate(!rv$confirm_module)
}
})
observeEvent(rv$confirm_module,{
confirmSweetAlert(
session = session,inputId = session$ns("show_confirmation"),title = "Be careful,your changes might be lost",text = "Do you want to save your changes?",type = "question",btn_labels = c("Cancel","Save"),btn_colors = NULL,closeOnClickOutside = FALSE,showCloseButton = FALSE,html = FALSE
)
cat("confirmation module")
rv$save_module <- isolate(!rv$save_module)
})
observeEvent(rv$save_module,{
if (isTRUE(input$show_confirmation)) {
sendSweetAlert(
session = session,title = "Saved",text = "Updated data has been successfully saved",type = "success"
)
rv$table_change <- isolate(!rv$table_change)
cat("saving module")
} else {
return()
}
})
data_to_modify <- eventReactive(rv$table_change,{
mtcars
})
handson_df <- eventReactive(rv$table_change,{
cat("create handsons")
req(data_to_modify())
rhandsontable(data_to_modify())
})
output$data_table <- renderRHandsontable({
cat("plot module")
req(handson_df())
htmlwidgets::onRender(handson_df(),change_hook)
})
}
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)