R shinydashboard——3.外观
1.皮肤
shinydashboard有很多颜色主题和外观的设置。默认为蓝色,可指定黑丝、紫色、绿色、红色和黄色,如dashboardPage(skin = "black")。
个人认为还是蓝色显得稳重一点。
2.注销面板
当使用Shiny Server Pro运行Shinydashboard应用程序并且登录了经过身份验证的用户时,在右上角将出现一个显示用户名和注销链接的面板。默认的Shiny Server Pro注销面板:

如果想改为添加具有动态UI(在服务器上生成)的用户面板,并隐藏默认的注销面板,如下所示:

library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
# Custom CSS to hide the default logout panel
tags$head(tags$style(HTML('.shiny-server-account { display: none; }'))),
# The dynamically-generated user panel
uiOutput("userpanel")
),
dashboardBody()
)
server <- function(input, output, session) {
output$userpanel <- renderUI({
# session$user is non-NULL only in authenticated sessions
if (!is.null(session$user)) {
sidebarUserPanel(
span("Logged in as ", session$user),
subtitle = a(icon("sign-out"), "Logout", href="__logout__"))
}
})
}
shinyApp(ui, server)
3.CSS
可以通过在应用程序中创建www/子目录,并在其中添加CSS文件,将自定义CSS添加到应用程序中。例如,想将dashboard的标题字体更改为与其余部分相同的字体,如下图所示:

首先创建一个名为www/custom.css的文件,包含以下内容:
.main-header .logo {
font-family: "Georgia", Times, "Times New Roman", serif;
font-weight: bold;
font-size: 24px;
}
然后从UI引用该CSS文件:
## ui.R ##
dashboardPage(
dashboardHeader(title = "Custom font"),
dashboardSidebar(),
dashboardBody(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
)
)
)
或者直接将CSS脚本嵌套再UI代码中:
## ui.R ##
dashboardPage(
dashboardHeader(title = "Custom font"),
dashboardSidebar(),
dashboardBody(
tags$head(tags$style(HTML('
.main-header .logo {
font-family: "Georgia", Times, "Times New Roman", serif;
font-weight: bold;
font-size: 24px;
}
')))
)
)
更多CSS的个性化设置可参考:Style your apps with CSS
4. 标题延长
很多情况下,shinydashboard使用的标题会超出标题栏中的默认宽度。可以使用titleWidth增加宽度。
如下图,将标题增加到450像素,并且通过使用自定义CSS将标题区域的背景色设置为与标题栏的其余部分相同:

shinyApp(
ui = dashboardPage(
dashboardHeader(
title = "Example of a long title that needs more space",
titleWidth = 450
),
dashboardSidebar(),
dashboardBody(
# Also add some custom CSS to make the title background area the same
# color as the rest of the header.
tags$head(tags$style(HTML('
.skin-blue .main-header .logo {
background-color: #3c8dbc;
}
.skin-blue .main-header .logo:hover {
background-color: #3c8dbc;
}
')))
)
),
server = function(input, output) { }
)
5.侧边栏宽度
通过使用width参数。

shinyApp(
ui = dashboardPage(
dashboardHeader(
title = "Title and sidebar 350 pixels wide",
titleWidth = 350
),
dashboardSidebar(
width = 350,
sidebarMenu(
menuItem("Menu Item")
)
),
dashboardBody()
),
server = function(input, output) { }
)
6.图标
Shiny和Shinydashboard中使用的图标实际上只是特殊字体集中的字符,它们是由Shiny的icon()创建的。
icon("calendar")
对应的HTML
<i class="fa fa-calendar"></i>
默认情况下,icon()使用的是Font-Awesome中的图标,如果要使用Glyphicons,需要指定lib="glyphicon":
"Calendar from Font-Awesome:", icon("calendar"),
"Cog from Glyphicons:", icon("cog", lib = "glyphicon")

来自Font-Awesome的图标:http://fontawesome.io/icons/
来自Glyphicons的图标: http://getbootstrap.com/components/#glyphicons
7.状态和颜色
Shinydashboard组件的状态参数status,是某些Bootstrap类的属性。如status="primary",status="success":

Shinydashboard组件的颜色参数color,如color="red",color="black":

更多状态和颜色通过?validStatuses和?validColors查看。
Ref:
https://rstudio.github.io/shinydashboard/appearance.html
R shinydashboard——3.外观的更多相关文章
- R shinydashboard ——2. 结构
目录 1.Shiny和HTML 2.结构 3. 标题Header 4. 侧边栏Siderbar 5.主体/正文Body box tabBox infoBox valueBox Layouts 1.Sh ...
- R shinydashboard ——1. 基本用法
shiny和shinydashboard使用虽然简单,但控件众多,需及时总结归纳. install.packages("shinydashboard") shinydashboar ...
- [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes
################## Rancher v2.1.7 + Kubernetes 1.13.4 ################ ##################### ...
- 利用python进行数据分析2_数据采集与操作
txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...
- Django项目:CRM(客户关系管理系统)--81--71PerfectCRM实现CRM项目首页
{#portal.html#} {## ————————46PerfectCRM实现登陆后页面才能访问————————#} {#{% extends 'king_admin/table_index.h ...
- Building [Security] Dashboards w/R & Shiny + shinydashboard(转)
Jay & I cover dashboards in Chapter 10 of Data-Driven Security (the book) but have barely mentio ...
- shinydashboard包---为shiny提供BI框架
1.安装 install.packages("shinydashboard") 2.基础知识 仪表盘有三个部分:标题.侧边栏,身体.下面是最最小的仪表面板页面的UI: ## ui. ...
- R语言包翻译——翻译
Shiny-cheatsheet ...
- R语言包翻译
Shiny-cheatsheet 作者:周彦通 1.安装 install.packages("shinydashboard") 2.基础知识 仪表盘有三个部分:标题.侧边栏,身体 ...
随机推荐
- 数字设计中的时钟与约束(gate)
转载:https://www.cnblogs.com/IClearner/p/6440488.html 最近做完了synopsys的DC workshop,涉及到时钟的建模/约束,这里就来聊聊数字中的 ...
- Python pylint requires Python '>=3.4.*' but the running Python is 2.7.12
用pylint 1.9.x 安装 pip install pylint==1.9.3. 或者换源 pip install -i https://pypi.tuna.tsinghua.edu.cn/si ...
- gas-station leetcode C++
There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You ...
- Ubuntu 安装 mysql 报错 "update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在"
解决方法: sudo cp /etc/mysql/my.cnf /etc/mysql/mysql.cnf 偷梁换柱-! 如果想更新mysql的源方法如下: wget http://dev.mysql. ...
- DOS常用基本命令
通配符* 和 ? *表示一个字符串 ?只代表一个字符 注意通配符只能通配文件名或扩展名,不能全都表示.例如我们要查找以字母y开头的所有文件,可以输入以下命令: dir y*.* 例如我要查找第二个字母 ...
- Springboot 整合RabbitMq ,用心看完这一篇就够了
该篇文章内容较多,包括有rabbitMq相关的一些简单理论介绍,provider消息推送实例,consumer消息消费实例,Direct.Topic.Fanout的使用,消息回调.手动确认等. (但是 ...
- 概述C# virtual修饰符
摘要:C#是继C++和Java语言后的又一面向对象的语言,在语法结构,C#有很多地方和C++及Java相似,但是又不同于它们,其中一些关键特别需要引起我们的注意. C# virtual修饰符用于修改方 ...
- Python基础(dict与set)
#和list比较,dict有以下几个特点: #查找和插入的速度极快,不会随着key的增加而变慢: #需要占用大量的内存,内存浪费多. #dict1 = {'傻狗1':100,'傻狗2':200,'傻狗 ...
- 面试官:咱们来聊一聊mysql主从延迟
背景 前段时间遇到一个线上问题,后来排查好久发现是因为主从同步延迟导致的,所以今天写一篇文章总结一下这个问题希望对你有用.如果觉得还不错,记得加个关注点个赞哦 思维导图 思维导图 常见的主从架构 随着 ...
- Windows11下的快捷键(win10通用,部分win11独有的不通用)
给大家介绍一下win11下我常用的几个快捷键,在微软官方的文档里面都可以查到,官网链接 https://support.microsoft.com/zh-cn/windows/windows-%E7% ...