4

My shiny dashboard app takes 1.20 mins to load as it has many tabs and each tab uses a subset of the database. I tried using the example shown here. My code is as follows:

In global.R

load_data <- function() {
    Sys.sleep(80)
    hide("loading_page")
    show("tab-content")
}

In ui.R

ui <- dashboardPage(skin = "green",
                    dashboardHeader(
                        title = "ABC",titleWidth = 225
                    ),
                    dashboardSidebar(
                        width = 225,
                        sidebarMenu(id = "tabs",
                                    menuItem("MY MONTHLY REPORTS", tabName = "myweeklyrep", icon = shiny::icon("compass")),
                        )
                    ),
                    dashboardBody(
                                  fluidPage(
                                      useShinyjs(),
                                      div(
                                          id = "loading_page",
                                          h4("Loading data...Please wait...")
                                      ),
                                      hidden(
                                          div(
                                              id = "tab-content"  
                                          )
                                      )
                                  ),
                                  tabItems(
                                      tabItem(
                                          tabName="myweeklyrep",

                                         #the UI code continues

In server.R

                  server <- function(input, output, session) ({
                                         session$onSessionEnded(function(){
                                             stopApp()
                                         })
                                         load_data()

I face two different problems:

  1. The tab-content page (the first page that loads) still shows, and
  2. The loading of database actually sleeps for 30 seconds and starts post that increasing the time that takes to load the app to 1 min 50 secs.

Don't know where I am going wrong.

Community
  • 1
  • 1
popeye
  • 281
  • 5
  • 20

0 Answers0