I'm trying to use show_modal_spinner to to display a text message while the model runs to generate outputs, I'm using PLS-PM in single obsereveEvent function but the showModal popup flashes for a second and disappears while the observe event function is still running, I'm getting all the results from this event but the Modal spinner vanishes as soon as I click the run button. Below is the observe event function I'm using. Please help in in debugging this code.
#------------------PLSPM Analysis Function------------------------
observeEvent({input$actionButton_PLSPM_analysis}, {
show_modal_spinner(
spin = "cube-grid",
color = "firebrick",
text = "Please wait..."
)
PLSPM_result_data_sym <- reactive({
readData(exps=input$PLSPM_ProtocolSelection, crop=input$PLSPM_CropSelection, country=input$PLSPM_CountrySelection, sym = input$PLSPM_TreatmentSelection)
})
PLSPM_Model_Analysis <- reactive({run_PLSPM_Analysis(PLSPM_result_data_sym(), input$PLSPM_CropSelection)})
PLSPM_summary <- reactive({(PLSPM_Model_Analysis()$summary)})
PLSPM_inner_model <- reactive({innerplot(PLSPM_Model_Analysis()$model, colpos = "#6890c4BB", colneg = "#f9675dBB",
box.prop = 0.55, box.size = 0.08, box.cex = 1,
box.col = "gray95", lcol = "black", box.lwd = 2,
txt.col = "black", shadow.size = 0, curve = 0,
lwd = 3, arr.pos = 0.5, arr.width = 0.2, arr.lwd = 3,
cex.txt = 0.9)})
PLSPM_Weight_plot <- reactive({outerplot(PLSPM_Model_Analysis()$model, colpos = "#6890c4BB", colneg = "#f9675dBB",
box.prop = 0.55, box.size = 0.08, box.cex = 1,
box.col = "gray95", lcol = "black", box.lwd = 2,
txt.col = "black", shadow.size = 0, curve = 0,
lwd = 3, arr.pos = 0.5, arr.width = 0.2, arr.lwd = 3,
cex.txt = 0.9)})
PLSPM_Loading_plot <- reactive({outerplot(PLSPM_Model_Analysis()$model, colpos = "#6890c4BB", colneg = "#f9675dBB",
box.prop = 0.55, box.size = 0.08, box.cex = 1,
box.col = "gray95", lcol = "black", box.lwd = 2,
txt.col = "black", shadow.size = 0, curve = 0,
lwd = 3, arr.pos = 0.5, arr.width = 0.2, arr.lwd = 3,
cex.txt = 0.9)})
mydf_inner_model <- reactive({as.data.frame(PLSPM_summary()$inner_model$pyield)})
mydf_outer_model <- reactive({as.data.frame(PLSPM_summary()$outer_model)})
output$data_table_inner_model <- renderDataTable({
datatable(mydf_inner_model(),options = list(
scrollX = TRUE))
})
output$data_table_outer_model <- renderDataTable({
datatable(mydf_outer_model(),options = list(
scrollX = TRUE))
})
output$plot_PLSPM_inner_model <- renderPlot({
(PLSPM_inner_model())
})
output$plot_PLSPM_Weight_plot <- renderPlot({
(PLSPM_Weight_plot())
})
output$plot_PLSPM_Loading_plot <- renderPlot({
(PLSPM_Loading_plot())
})
remove_modal_spinner()
})
That's because you define
reactiveinside anobserveEvent. When you usePLSPM_result_data_sym <- reactive(...)it does not do the calculation, it is simply registered to be done later (when you callPLSPM_result_data_sym()). Instead you can usereactiveValueslike this (and put theoutputoutside theobserveEventtoo):