Shiny-cheatsheet

                                                                                                                 作者:贾慧   作品来源:百度百科

.炫酷外观

皮肤skins

仪表盘包括很多的主题或者皮肤。默认的为blue蓝色,此外,还有其他的颜色,包括:black黑色,purple紫色,green绿色,red红色,yellow黄色等。可以使用dashboardPage(skin = "blue"), dashboardPage(skin = "black")等进行设置。

ui <- dashboardPage(skin = "black",

dashboardHeader(title = "Value boxes"),

dashboardSidebar(),

dashboardBody()

)

注销面板logout panel

(这需要shinydashboard 0.5.1或更高版本显示。)当shinydashboard应用运行shiny服务器之前,需要经过身份验证的用户才能登录,面板在右上角显示用户名和注销链接。

注销面板与shinydashboard更很好地集成。正如你所看到的在上面的截图中,默认注销面板部分掩盖了下拉菜单图标。我们可以添加一个用户面板与动态UI(在服务器上生成)和隐藏默认注销面板,如下所示:

程序:

library(shiny)

library(shinydashboard)

library(httr)

library(jsonlite)

library(data.table)

library(dplyr)

library(rvest)

library(magrittr)

ui <- dashboardPage(

dashboardHeader(

title = "SSP logout",

dropdownMenu(type = "messages", badgeStatus = "success",

messageItem("Message 1", "Content of a message.")

)

),

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"),

sidebarMenu(

menuItem("Menu item 1", icon = shiny::icon("calendar"))

)

),

dashboardBody()

)

server <- function(input, output, session) {

# Generate the dynamic UI for the logout panel

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)

其他程序:

library(shiny)

library(shinydashboard)

library(httr)

library(jsonlite)

library(data.table)

library(dplyr)

library(rvest)

library(magrittr)

header <- dashboardHeader(title="CYBER Dashboard")

sidebar <- dashboardSidebar()

body <- dashboardBody(

fluidPage(

fluidRow(

a(href="http://isc.sans.org/",

target="_blank", uiOutput("infocon")),

a(href="http://www.symantec.com/security_response/threatcon/",

target="_blank", uiOutput("threatcon")),

a(href="http://webapp.iss.net/gtoc/",

target="_blank", uiOutput("alertcon"))

)

)

)

ui <- dashboardPage(header, sidebar, body, skin="black")

server <- function(input, output) {

output$infocon <- renderUI({

infocon_url <- "https://isc.sans.edu/api/infocon?json"

infocon <- fromJSON(content(GET(infocon_url)))

valueBox(

value="Yellow",

subtitle="SANS Infocon",

icon=icon("bullseye"),

color=ifelse(infocon$status=="test", "blue", infocon$status)

)

})

output$threatcon <- renderUI({

pg <- html("http://www.symantec.com/security_response/#")

pg %>%

html_nodes("div.colContentThreatCon > a") %>%

html_text() %>%

extract(1) -> threatcon_text

tcon_map <- c("green", "yellow", "orange", "red")

names(tcon_map) <- c("Level 1", "Level 2", "Level 3", "Level 4")

threatcon_color <- unname(tcon_map[gsub(":.*$", "", threatcon_text)])

threatcon_text <- gsub("^.*:", "", threatcon_text)

valueBox(

value=threatcon_text,

subtitle="Symantec ThreatCon",

icon=icon("tachometer"),

color=threatcon_color

)

})

output$alertcon <- renderUI({

pg <- html("http://xforce.iss.net/")

pg %>%

html_nodes(xpath="//td[@class='newsevents']/p") %>%

html_text() %>%

gsub(" -.*$", "", .) -> alertcon_text

acon_map <- c("green", "blue", "yellow", "red")

names(acon_map) <- c("AlertCon 1", "AlertCon 2", "AlertCon 3", "AlertCon 4")

alertcon_color <- unname(acon_map[alertcon_text])

valueBox(

value=alertcon_text,

subtitle="IBM X-Force",

icon=icon("warning"),

color=alertcon_color

)

})

}

shinyApp(ui, server)

CSS

You can add custom CSS to your app by creating a www/ subdirectory to your app and adding a CSS file there. Suppose, for example, you want to change the title font of your dashboard to the same font as the rest of the dashboard, so that it looks like this:

To do this, first create a file named www/custom.css with the following:

.main-header .logo {

font-family: "Georgia", Times, "Times New Roman", serif;

font-weight: bold;

font-size: 24px;

}

Then refer to that CSS file from the UI of your app:

## ui.R ##

dashboardPage(

dashboardHeader(title = "Custom font"),

dashboardSidebar(),

dashboardBody(

tags$head(

tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")

)

)

)

A second way to include CSS is to put it directly in the UI code for your app:

## 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;

}

')))  )

)

4.4长标题

In some cases, the title that you wish to use won’t fit in the default width in the header bar. You can make the space for the title wider with the titleWidth option. In this example, we’ve increased the width for the title to 450 pixels, and also set the background color of the title area (using custom CSS) to be the same as the rest of the header bar.

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 {

}

.skin-blue .main-header .logo:hover {

background-color: #3c8dbc;

}

')))    )

),

server = function(input, output) { }

)

侧边栏宽度sidebar width

To change the width of the sidebar, you can use the width option. This example has a wider title and sidebar:

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) { }

)

R语言包翻译——翻译的更多相关文章

  1. R语言包在linux上的安装等知识

    有关install.packages()函数的详见:R包 package 的安装(install.packages函数详解) R的包(package)通常有两种:1 binary package:这种 ...

  2. R语言 包

    R语言包 R语言的包是R函数,编译代码和样本数据的集合. 它们存储在R语言环境中名为"library"的目录下. 默认情况下,R语言在安装期间安装一组软件包. 随后添加更多包,当它 ...

  3. R语言——包的添加和使用

    R是开源的软件工具,很多R语言用户和爱好者都会扩展R的功能模块,我们把这些模块称为包.我们可以通过下载安装这些已经写好的包来完成我们需要的任务工作. 包下载地址:https://cran.r-proj ...

  4. R语言包的安装

    pheatmap包的安装 1: 首先R语言的安装路径里面最好不要有中文路径 2: 在安装其他依存的scales和colorspace包时候要关闭防火墙 错误提示: 试开URL'https://mirr ...

  5. Windows下使用Rtools编译R语言包

    使用devtools安装github中的R源代码时,经常会出各种错误,索性搜了一下怎么在Windows下直接打包,网上的资料也是参差不齐,以下是自己验证通过的. 一.下载Rtools 下载地址:htt ...

  6. r语言 包说明

    [在实际工作中,每个数据科学项目各不相同,但基本都遵循一定的通用流程.具体如下]   [下面列出每个步骤最有用的一些R包] 1.数据导入以下R包主要用于数据导入和保存数据:feather:一种快速,轻 ...

  7. R语言包相关命令

    R的包(package)通常有两种:1 binary package:这种包属于即得即用型(ready-to-use),但是依赖与平台,即Win和Linux平台下不同.2 Source package ...

  8. R语言包翻译

    Shiny-cheatsheet 作者:周彦通 1.安装 install.packages("shinydashboard")  2.基础知识 仪表盘有三个部分:标题.侧边栏,身体 ...

  9. R语言包_dplyr_1

    有5个基础的函数: - filter - select - arrange - mutate - summarise - group_by (plus) 可以和databases以及data tabl ...

随机推荐

  1. WebView加载页面的两种方式——网络页面和本地页面

    WebView加载页面的两种方式 一.加载网络页面 加载网络页面,是最简单的一种方式,只需要传入http的URL就可以,实现WebView加载网络页面 代码如下图: 二.加载本地页面 1.加载asse ...

  2. NodeJS+Express+MongoDB 简单实现数据录入及回显展示【适合新人刚接触学习】

    近期在看NodeJS相关 不得不说NodeJS+Express 进行网站开发是很不错,对于喜欢玩JS的来说真是很好的一种Web开发组合 在接触NodeJS时受平时Java或者C#中API接口等开发的思 ...

  3. [js笔记整理]DOM 篇

    一.节点类型 1.元素节点:HTML元素 2.文本节点:元素标签中的内容 3.属性节点:元素的属性 (检测节点类型:node.nodeType //元素=1,属性=2,文本=3) 二.使用DOM获取元 ...

  4. 最新的chart 聊天功能( webpack2 + react + router + redux + scss + nodejs + express + mysql + es6/7)

    请表明转载链接: 我是一个喜欢捣腾的人,没事总喜欢学点新东西,可能现在用不到,但是不保证下一刻用不到. 我一直从事的是依赖angular.js 的web开发,但是我怎么能一直用它呢?看看最近火的一塌糊 ...

  5. 分布式缓存技术redis学习—— 深入理解Spring Redis的使用

    关于spring redis框架的使用,网上的例子很多很多.但是在自己最近一段时间的使用中,发现这些教程都是入门教程,包括很多的使用方法,与spring redis丰富的api大相径庭,真是浪费了这么 ...

  6. 第一篇:使用Spark探索经典数据集MovieLens

    前言 MovieLens数据集包含多个用户对多部电影的评级数据,也包括电影元数据信息和用户属性信息. 这个数据集经常用来做推荐系统,机器学习算法的测试数据集.尤其在推荐系统领域,很多著名论文都是基于这 ...

  7. Day1-三元运算及

    三元运算:result = Value1 if Condition else Vlaue2 >>> a,b,c = 1,3,5>>> d = a if a > ...

  8. 写给Android App开发人员看的Android底层知识(3)

    (七)App启动流程第2篇 书接上文,App启动一共有七个阶段,上篇文章篇幅所限,我们只看了第一阶段,接下来讲剩余的六个阶段,仍然是拿斗鱼App举例子. 简单回顾一下第一阶段的流程,就是Launche ...

  9. 《Android进阶》之第二篇 launcher

    public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params, boolean ...

  10. Spring MVC和Struts2的比较

    Spring MVC PK Struts2 我们用struts2时采用的传统的配置文件的方式,并没有使用传说中的0配置.spring3 mvc可以认为已经100%零配置了(除了配置spring mvc ...