shinydashboard安装、使用指南
2020-10-07 本文已影响0人
JeremyL
shinydashboard 的主要目的是帮助用户更方便构建Shiny app的布局。
Dashboard#shinydashboard安装
install.packages("shinydashboard")
#基本情况
shinydashboard最基本的组成有3个部分,
- a header
- a sidebar
- a body
##基本面板
## ui.R ##
library(shinydashboard)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
Blank dashboard
##添加内容
###添加内容到主页面
## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
[站外图片上传中...(image-2c8c0-1602061295182)]
###添加内容到侧边栏
shinydashboard 中添加menu items与shiny中tabPanel
作用类似:当单击一个侧边栏的一个对象时,它会在主页面显示一组不同的内容。
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
)
在主页面需要页面与menuItem一一进行对应,通过设置tabItems中的tabItem
对应各个menuItem的tabName。
## Body content
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")
)
)
)
Basic dashboard with tabs 1
#原文
系列文章:
R shiny教程-1:一个 Shiny app的基本组成部分
R shiny教程-2:布局用户界面
R shiny教程-3:添加小部件到Shiny App
R shiny教程-4:Shiny app响应式结果展示
R shiny教程-5:调用R程序和导入数据
R shiny教程-6:使用响应表达式reactive()
R shiny教程-7:共享Shiny app
Shiny Server安装