I have initial loading of data from the DB in the server.R
which takes a few seconds. Until this is done, the page displayed is distorted (wrong data in selection box, and weird placing of the boxes, see below).
I want to display a different page (or at least different content in my first-displayed tab) until the data is completely loaded.
I thought about doing some kind of conditionalPanel
using a condition based on a dedicated global variable (initial_loading_done), but wherever I tried placing the conditionalPanel
it didn't work.
This is the structure of my UI.R:
shinyUI(
dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
sidebarMenu(
menuItem("Tab1", tabName = "Tab1",icon = icon("dashboard")),
menuItem("Tab2", tabName = "Tab2", icon = icon("bar-chart-o"))
)
),
dashboardBody(
includeCSS("custom_css.css"),
tabItems(
tabItem(tabName = "Tab1",
fluidRow(<content>),
mainPanel(
fluidRow(<content>)
)
),
tabItem(tabName = "Tab2",
fluidRow(<content>),
mainPanel(
dataTableOutput('my_data_table')
)
)
)
)
)
)
In
server
I like to usereactiveValues()
to store asetupComplete
condition. Then, when the data is loaded mysetupComplete
is set toTRUE
.In the
ui
we can then assess thissetupComplete
condition in aconditionalPanel
, and only display the content (in my example the threebox()
widgets).Here's a working example
Here's a very simple example using
shinyjs
packageThe idea is to create the loading "page" and the content "page" under different IDs, have the content page initially hidden, and use
show()
andhide()
after the app is readyThe code
doesn't work with tabsetPanel. But if you move the id to the div level it works beautifully. Thanks to shinyjs author Dean Attali for this tip. https://stackoverflow.com/users/4432127/keshete