我正在尝试在shinydashboard中创建一个启动或着陆页(如有必要,可以创建闪亮的页面)。我的主要闪亮应用程序将有标签导航等但着陆页不应。事实上,它应该完全不同,可能类似于:http://www.dataseries.org
我知道我可以将html页面添加到与ui.r和server.r脚本相同的文件夹中,但是在应用程序启动时我还没有找到引用该文件的方法。锚标记可以在那里提供链接,但我希望在调用页面时自动打开登录页面。
我可重复的代码是毫无价值的,因为没有任何工作,但我总是把它包括在内,以防它变得更容易。这是来自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)
})
}
答案 0 :(得分:6)
它有点被黑客攻击,但你可以使用模态对话框来复制目标网页。
基本上,使用Shiny的本地showModal(modalDialog())
命令在应用程序上弹出一个面板。模态是在observeEvent()
中的server.R
语句中创建的,该语句在应用启动时只运行一次。自定义CSS包含在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 强>
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)
})
}
一些警告:
我相信您可以通过查找与加载应用程序的服务器相对应的事件来修复后者,但不幸的是我不熟悉任何此类事件。
答案 1 :(得分:0)
在此示例中,我使用了隐藏的 tabsetPanel()
来创建登录页面。它包含 2 个标签
默认情况下,它会在应用加载时加载着陆页。然后可以使用 updateTabsetPanel()
从登录页面切换到内容。
ui.R
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabsetPanel(
id = "page",
type = "hidden",
#Your landing page
tabPanelBody("landing-page",
div(
style = "position: absolute;
left: 0;
top: 0;
z-index: 10000;
width: 100%;
height: 100%;
background: lightblue;",
div(
style = "position: relative;
top: 30%;
left: 30%;",
h1("Landing Page"),
textInput("search", NULL),
#Button to close landing page
actionButton("close-landing-page", "Close")
)
)
),
#Your content
tabPanelBody("content",
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, session) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
#Observe event to close landing page and open content
observeEvent(input$`close-landing-page`, {
updateTabsetPanel(session, "page", "content")
})
}