简体   繁体   English

闪亮应用的登陆页面

[英]landing page for shiny app

I am trying to create a splash or landing page in shinydashboard (or shiny if necessary). 我正在尝试在shinydashboard中创建一个启动或着陆页(如果需要,可以创建闪亮的页面)。 My main shiny app will have tab navigation etc. but the landing page should not . 我的主要闪亮应用程序将有标签导航等, 但登陆页面不应该 In fact, it should be completely different, maybe similar to this: http://www.dataseries.org 事实上,它应该完全不同,可能类似于: http//www.dataseries.org

I know that I can add html pages into the same folder as the ui.r and server.r scripts but I have not found a way to reference that file when the app is starting up. 我知道我可以将html页面添加到与ui.r和server.r脚本相同的文件夹中,但是当应用程序启动时我还没有找到引用该文件的方法。 An anchor tag could provide a link there but I want the landing page to automatically open when the page is called. 锚标记可以在那里提供链接,但我希望登录页面在调用页面时自动打开。

My reproducible code is pretty worthless because nothing has worked but I include it anyways, in case it make anything easier. 我可重复的代码是没有价值的,因为没有任何工作,但我还是包括它,以防它变得更容易。 This is boilerplate from the shinydashboard site. 这是来自shinydashboard网站的样板。

ui.r 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 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)
      })
    }

It's a bit hacked-together, but you can use a modal dialog to replicate a landing page. 它有点被黑客攻击,但您可以使用模态对话框来复制着陆页。

Basically, use Shiny's native showModal(modalDialog()) command to have a panel pop up over the app. 基本上,使用Shiny的原生showModal(modalDialog())命令在应用程序上弹出一个面板。 The modal is created in an observeEvent() statement in server.R that runs exactly once when the app starts up. 该模式是在创建observeEvent()在声明中server.R运行恰好一次,当应用程序启动。 Custom CSS is included in the ui.R script that makes the modal take up the entire page. 自定义CSS包含在ui.R脚本中,使模式占用整个页面。 Here's the app: 这是应用程序:

ui.R 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 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: 一些警告:

  • The CSS alters every modal dialog in the app, so you will need to add specific classes to this first modal to prevent all modals from being full-screen. CSS改变了应用程序中的每个模态对话框,因此您需要向第一个模态添加特定类以防止所有模态全屏。
    • The modal technically loads after the UI loads, so there is a short second where the user can see the app in the background. 在加载UI之后技术上加载模态,因此用户可以在后台看到应用程序。

I believe you may be able to fix the latter by looking for an event that corresponds to the server loading the app, but unfortunately I am not familiar with any such event. 我相信您可以通过查找与加载应用程序的服务器相对应的事件来修复后者,但不幸的是我不熟悉任何此类事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM