我正在尝试在shinydashboard中创建一个启动或着陆页(如果需要,可以创建闪亮的页面)。我的主要闪亮应用程序将有标签导航等,但登陆页面不应该。事实上,它应该完全不同,可能类似于:http://www.dataseries.org
我知道我可以将html页面添加到与ui.r和server.r脚本相同的文件夹中,但是当应用程序启动时我还没有找到引用该文件的方法。锚标记可以在那里提供链接,但我希望登录页面在调用页面时自动打开。
我可重复的代码是没有价值的,因为没有任何工作,但我还是包括它,以防它变得更容易。这是来自shinydashboard网站的样板。
长子。 [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)
})
}
它有点被黑客攻击,但您可以使用模态对话框来复制着陆页。
基本上,使用Shiny的本机showModal(modalDialog())
命令在应用程序上弹出一个面板。模态是在observeEvent()
中的server.R
语句中创建的,该语句在应用程序启动时只运行一次。自定义CSS包含在ui.R
脚本中,使得模式占用整个页面。这是应用程序:
长子。 [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)
})
}
一些警告:
我相信您可以通过查找与加载应用程序的服务器相对应的事件来修复后者,但不幸的是我不熟悉任何此类事件。