Spinner loading before action button is pressed

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)

you can pass a NULL renderDT to Test so that it 'renders' , thereby not spinning.
Then when you observe event, you redefine Test to render your desired table

server <- function(input, output, session) {
  
  output$Test <- DT::renderDT(NULL)
  
  observeEvent(input$plot, {
    output$Test <- DT::renderDT(DT::datatable(head(iris),
      rownames = FALSE, options = list(
        dom = "t",
        ordering = FALSE
      )
    ))
  })
}

hi Nir,

Great help thanks a lot for your time.

Hi Nir,

Right now, we see the loading at the center, IS there a way to make it at the top? please help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.