Below is the sample application where I have put spinner loading. But the issue is , even before the action button is pressed, the spinner is been seen. Actually, only when action button is pressed, it should come. I know this can be achieved by adding eventReactive, but is there a way to achieve this only by using observeEvent
library(shiny)
library(dplyr)
library(shinycssloaders)
library(DT)
ui <- fluidPage(
actionButton("plot","plot"),
withSpinner(dataTableOutput("Test"),color="black")
)
server <- function(input, output, session) {
observeEvent(input$plot, {
output$Test <- DT::renderDT(DT::datatable(head(iris),
rownames = FALSE, options = list(dom = 't',
ordering=FALSE)))
})
}
shinyApp(ui = ui, server = server)
One solution is to use uiOutput so that the ui for the spinner and the table are created only when you click on the button:
library(shiny)
library(dplyr)
library(shinycssloaders)
library(DT)
ui <- fluidPage(
actionButton("plot","plot"),
uiOutput("spinner")
)
server <- function(input, output, session) {
observeEvent(input$plot, {
output$spinner <- renderUI({
withSpinner(dataTableOutput("Test"), color="black")
})
output$Test <- DT::renderDT({
Sys.sleep(3)
DT::datatable(head(iris),
rownames = FALSE, options = list(dom = 't', ordering=FALSE))
})
})
}
shinyApp(ui = ui, server = server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With