Landing page for a brilliant app

I am trying to create a splash or landing page in a shinydashboard (or, if necessary, brilliant). My main shiny app will have a navigation tab, etc. but the landing page should not . In fact, it should be completely different, it might look like this: http://www.dataseries.org

I know that I can add html pages to the same folder as the ui.r and server.r scripts, but I did not find a way to link to this file when the application starts. An anchor tag may contain a link, but I want the landing page to automatically open when the page is called.

My reproducible code is pretty useless because nothing worked, but I still enable it if it makes anything easier. This is a template from shinydashboard.

ui.r

library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), ## ui.R ## dashboardSidebar( sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Widgets", tabName = "widgets", icon = icon("th")) ) ), dashboardBody( tabItems( # First tab content tabItem(tabName = "dashboard", fluidRow( box(plotOutput("plot1", height = 250)), box( title = "Controls", sliderInput("slider", "Number of observations:", 1, 100, 50) ) ) ), # Second tab content tabItem(tabName = "widgets", h2("Widgets tab content") ) ) ) ) 

server.r

  library(shiny) library(shinydashboard) server <- function(input, output) { set.seed(122) histdata <- rnorm(500) output$plot1 <- renderPlot({ data <- histdata[seq_len(input$slider)] hist(data) }) } 
+6
source share
1 answer

A bit hacky, but you can use the modal dialog to replicate the landing page.

Basically, use the Shiny native showModal(modalDialog()) command so that the panel showModal(modalDialog()) up over the application. The modal is created in the observeEvent() server.R in server.R , which starts exactly once when the application starts. Custom CSS is included in the ui.R script, which makes the modal coverage of the entire page. Here is the application:

ui.R

 library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), ## ui.R ## dashboardSidebar( sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Widgets", tabName = "widgets", icon = icon("th")) ) ), dashboardBody( tags$head(tags$style(HTML(' .modal.in .modal-dialog{ width:100%; height:100%; margin:0px; } .modal-content{ width:100%; height:100%; } '))), tabItems( # First tab content tabItem(tabName = "dashboard", fluidRow( box(plotOutput("plot1", height = 250)), box( title = "Controls", sliderInput("slider", "Number of observations:", 1, 100, 50) ) ) ), # Second tab content tabItem(tabName = "widgets", h2("Widgets tab content") ) ) ) ) 

server.R

 library(shiny) library(shinydashboard) server <- function(input, output) { set.seed(122) histdata <- rnorm(500) observeEvent(once = TRUE,ignoreNULL = FALSE, ignoreInit = FALSE, eventExpr = histdata, { # event will be called when histdata changes, which only happens once, when it is initially calculated showModal(modalDialog( title = "Landing Page", h1('Landing Page'), p('Theoretically you can put whatever content you want in here') )) }) output$plot1 <- renderPlot({ data <- histdata[seq_len(input$slider)] hist(data) }) } 

A few caveats:

  • CSS changes every modal dialog in the application, so you will need to add certain classes to this first modal moment so that all modals are not full-screen.
    • It modally technically loads after loading the user interface, so there is a short second when the user can see the application in the background.

I believe that you can fix the latter by looking at the event corresponding to the server loading the application, but, unfortunately, I am not familiar with any such event.

+2
source

Source: https://habr.com/ru/post/1011491/


All Articles