Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >基于shinydashboard搭建你的仪表板(五)

基于shinydashboard搭建你的仪表板(五)

作者头像
1480
发布于 2019-06-03 08:31:17
发布于 2019-06-03 08:31:17
2.3K00
代码可运行
举报
文章被收录于专栏:数据分析1480数据分析1480
运行总次数:0
代码可运行

前言

承接系列四,这一节介绍一下主体中的4种box函数。顾名思义,box函数是在主体中创建一些对象框,而对象框内可以包含任何内容。

四种box函数

下面结合之前侧边栏以及主体布局简单介绍一下4种box函数。

box对象框

box对象框为基本对象框,用到的最多。函数为box(),函数中有几个常用的参数:

代码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(shiny)library(shinydashboard)library(ggplot2)
ui <- dashboardPage(  dashboardHeader(title = "WorkingNotes:Box"),    dashboardSidebar(      sidebarMenu(    menuItem("Plot1", tabName = "Plot1", icon = icon("dashboard")),    menuItem("Plot2", tabName = "Plot2", icon = icon("dashboard")),    menuItem("Plot3", tabName = "Plot3", icon = icon("dashboard")))),  dashboardBody(    tabItems(      tabItem(tabName = "Plot1",        fluidPage(          box("仅仅设置宽度为6"),          box("在上图基础上加上对象框title的背景颜色为red")        ),        fluidPage(          box(plotOutput("Plot"), width = 6),          box(plotOutput("Plot1"), status = "danger", width = 6))),      tabItem(tabName = "Plot2",              fluidPage(                box("在上图基础上加上背景颜色为green"),                box("在上图基础上加上最小化按钮")              ),              fluidPage(                box(plotOutput("Plot2"), status = "success",background = "green", width = 6),                box(plotOutput("Plot3"), status = "success",background = "green", collapsible = TRUE, width = 6))),            tabItem(tabName = "Plot3",              fluidPage(                box("在上图基础上加collapsed = TRUE,图形已经最小化"),                box("在上图基础上加上标题")              ),                fluidPage(                box(plotOutput("Plot4"),  status = "success", background = "green",collapsible = TRUE,                     collapsed = TRUE,width = 6),                box(plotOutput("Plot5"), status = "success", background = "green", collapsible = TRUE,                     collapsed = TRUE,title = "histogram", width = 6)))          )))
server <- function(input, output) {  set.seed(123)  data = diamonds[sample(1:nrow(diamonds), 10000, replace = F), ]  p <- renderPlot({    ggplot(data, aes(x = price, fill = cut)) +       geom_histogram(bins = 30) +      ggtitle("geom_histogram") +      theme(plot.title = element_text(hjust = 0.5)) + xlab("")  })    output$Plot <- p  output$Plot1 <- p  output$Plot2 <- p  output$Plot3 <- p  output$Plot4 <- p  output$Plot5 <- p}shinyApp(ui, server)

上述代码中:侧边栏创建3个菜单栏,每一个菜单栏对应的主体界面布局为基于行的主体布局,每一个界面的第一个行整体用于解释第二个行整体。

tabBox对象框

使用tabBox()函数创建具有选项卡的对象框,函数内使用tabPanel()创建不同的选项卡,tabPanel()内添加输出对象。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(shiny)library(shinydashboard)library(ggplot2)library(DT)sider <- dashboardSidebar(      sidebarMenu(      menuItem("tabbox1", tabName = "tabbox1", icon = icon("dashboard")),      menuItem("tabbox2", tabName = "tabbox2", icon = icon("dashboard")),      menuItem("tabbox3", tabName = "tabbox3", icon = icon("dashboard")))    )
body <- dashboardBody(  tabItems(  ###tabBox标题为tabbox1,宽度为12,高度为500px,其他参数为默认    tabItem(tabName = "tabbox1",             fluidRow(              tabBox(title = "tabbox1",height = "500px", width = 12,                tabPanel("plot", plotOutput("Plot")),                tabPanel("data", dataTableOutput("Data")))            )  ),    tabItem(tabName = "tabbox2",            fluidRow(            ###selected = "data",故data为活跃选项卡,side="right",选项卡呈现在右边              tabBox(title = "tabbox2",                side = "right", height = "500px", width = 12,                selected = "data",                tabPanel("plot", plotOutput("Plot1")),                tabPanel("data", dataTableOutput("Data1"))))          ),    tabItem(tabName = "tabbox3",          fluidRow(          ###selected="plot",故plot选项卡为活跃            tabBox(height = "500px", width = 12,selected = "plot",              title = tagList(shiny::icon("gear"), "tabbox3"),              tabPanel("data", dataTableOutput("Data2")),              tabPanel("plot", plotOutput("Plot2"))))          ))  )  ui <- dashboardPage(  dashboardHeader(title = "WorkingNotes:tabBox"),  sider,  body)
server = function(input, output) {  set.seed(123)  data = diamonds[sample(1:nrow(diamonds), 10000, replace = F), ]    p <- renderPlot({    ggplot(data, aes(x = price, fill = cut)) +       geom_histogram(position = "dodge", bins = 30) +      ggtitle("geom_histogram") +      theme(plot.title = element_text(hjust = 0.5)) + xlab("")  })    d <- renderDataTable({    datatable(data)  })  output$Plot <- p  output$Plot1 <- p  output$Plot2 <- p  output$Data <- d  output$Data1 <- d  output$Data2 <- d
}shinyApp(ui, server)

上图侧边栏创建3个菜单栏,三个菜单栏对应的主体界面都是基于行的布局。第一个菜单栏主体的tabBox设置标题为“tabbox1”,其他参数为默认值,故选项卡位于左侧,第一个选项卡plot为激活状态;第二个菜单栏主体设置side = "right“,故选项卡位置位于右侧,且设置selected = "data“,故data选项卡为激活状态;第三个菜单栏设置一下title,设置selected = "plot“,故plot选项卡为激活状态。

infoBox对象框

infoBox对象框和valueBox两者功能类似,而且用到的不多,故这里简单介绍一下。infoBox()函数中有一个逻辑参数fill决定对象框是否为纯色,有静态infoBox,使用infoBox()函数创建,有动态infoBox,使用成对的infoBoxouput()函数和激活函数renderInfoBox()创建。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(shinydashboard)
ui <- dashboardPage(  dashboardHeader(title = "WorkingNotes:Infoboxes"),  dashboardSidebar(),  dashboardBody(    ##fill为默认,非纯色填充    fluidRow(      # 静态infoBox      infoBox("New Orders", 10 * 2, icon = icon("credit-card")),      # 动态infoBoxes      infoBoxOutput("progressBox"),      infoBoxOutput("approvalBox")    ),        ##fill为TRue,纯色填充    fluidRow(      infoBox("New Orders", 10 * 2, icon = icon("credit-card"), fill = TRUE),      infoBoxOutput("progressBox2"),      infoBoxOutput("approvalBox2")    ),        fluidRow(      ##点击按钮,增加值      box(width = 4, "no actionButton"),      box(width = 4, actionButton("count", "Increment progress")),      box(width = 4, actionButton("count1", "Increment approval"))    )  ))
server <- function(input, output) {  output$progressBox <- renderInfoBox({    infoBox(      "Progress", paste0(25 + input$count, "%"), icon = icon("list"),      color = "purple"    )  })  output$approvalBox <- renderInfoBox({    infoBox(      "Approval", paste0(70 + input$count1, "%"), icon = icon("thumbs-up", lib = "glyphicon"),      color = "yellow"    )  })    ##与上面显示一样,唯一区别是实填充  output$progressBox2 <- renderInfoBox({    infoBox(      "Progress", paste0(25 + input$count, "%"), icon = icon("list"),      color = "purple", fill = TRUE    )  })  output$approvalBox2 <- renderInfoBox({    infoBox(      "Approval", paste0(70 + input$count1, "%"), icon = icon("thumbs-up", lib = "glyphicon"),      color = "yellow", fill = TRUE    )  })}
shinyApp(ui, server)

valueBox对象框

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(shinydashboard)
ui <- dashboardPage(  dashboardHeader(title = "WorkingNotes:Valueboxes"),  dashboardSidebar(),  dashboardBody(    fluidRow(      ##静态valuebox      valueBox(10 * 2, "New Orders", icon = icon("credit-card")),            ##动态valuebox      valueBoxOutput("progressBox"),            valueBoxOutput("approvalBox")    ),    fluidRow(      ##点击按钮,增加值      box(width = 4, "no actionButton"),      box(width = 4, actionButton("count", "Increment progress")),      box(width = 4, actionButton("count1", "Increment approval"))    )  ))
server <- function(input, output) {  output$progressBox <- renderValueBox({    valueBox(      "Progress", paste0(25 + input$count, "%"), icon = icon("list"),      color = "purple"    )  })    output$approvalBox <- renderValueBox({    valueBox(      "Approval", paste0(70 + input$count1, "%"), icon = icon("thumbs-up", lib = "glyphicon"),      color = "yellow"    )  })}
shinyApp(ui, server)

总结

到这里将shinydashborad的标题栏、侧边栏以及主体简单的介绍一下,可以开发出自己的shinyapp了。下面章节将介绍如何将shinyapp共享到服务器上以及对shinyapp加密,输入账号和密码才能访问shinyapp。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-06-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据分析1480 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
windows下安装ElasticSearch的Head插件
转载自https://www.cnblogs.com/hts-technology/p/8477258.html
allsmallpig
2021/02/25
5670
【elasticsearch系列】安装elasticsearch-head插件
安装elasticsearch-head插件,需要依赖nodeJs环境,故首先我们先搭建nodeJs环境; 此part先将此篇文章需要的各个官网列出来: node官网:https://nodejs.org/en/download/ node中文网:http://nodejs.cn/download/current/ elasticsearch-head GitHub:https://github.com/mobz/elasticsearch-head
沁溪源
2021/09/09
1.6K0
【elasticsearch系列】安装elasticsearch-head插件
windows下ElasticSearch学习(一)
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。
Wu_Candy
2022/07/04
4670
windows下ElasticSearch学习(一)
【ES三周年】linux-centos7安装elasticsearch-head插件
①从官网https://nodejs.org/en/download下载 node-v8.11.3-linux-x64.tar.xz
张同学tty
2023/04/03
1.6K0
【ES三周年】linux-centos7安装elasticsearch-head插件
基于windows平台搭建elasticsearch
elasticsearch-6.0.1.zip--https://www.elastic.co/downloads/elasticsearch
陈珙
2018/09/12
9890
基于windows平台搭建elasticsearch
windows10 安装 ElasticSearch
Elasticsearch 是一个分布式的 RESTful 风格的搜索和数据分析引擎。 Elastic (官网:https://www.elastic.co) 的底层是开源库 Lucene。但是,你没法直接用 Lucene,必须自己写代码去调用它的接口。Elastic 是 Lucene 的封装,提供了 REST API 的操作接口,开箱即用,通过简单的REST api 隐藏了lucene的复杂性,从而让全文搜索变得简单。
王图思睿
2021/06/16
1.2K0
Elasticsearch-5.5.0安装head插件
环境 Windows7 JDK-1.8 ElasticSearch-5.5.0 node-v8.1.2-x64.msi git客户端
試毅-思伟
2018/09/06
9640
Elasticsearch-5.5.0安装head插件
【Elasticsearch全文搜索引擎实战】之Head插件实践 简介1. ES 5.0+ 版本Head插件安装2. 配置3. 启动4. 访问5. 安全问题(严重)6. 小结
Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。它可以快速地储存、搜索和分析海量数据。维基百科、Stack Overflow、Github也都采用它做的搜索。 更多Elasticsearch的相关知识,请阅读官网《Elasticsearch: 权威指南》。
mantou
2019/02/13
1.1K0
【Elasticsearch全文搜索引擎实战】之Head插件实践
		简介1. ES 5.0+ 版本Head插件安装2. 配置3. 启动4. 访问5. 安全问题(严重)6. 小结
Windows安装ElasticSearch
下载地址:https://www.elastic.co/cn/downloads/elasticsearch
代码的路
2023/03/21
7700
Windows下安装ElasticSearch6.3.1以及Head插件
es5以上版本安装head需要安装node和grunt(之前的直接用plugin命令即可安装)
ZhangXianSheng
2019/05/28
2.2K0
elasticsearch-head插件安装
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动
lyb-geek
2018/12/05
3.6K0
蛋疼的ElasticSearch(二)之配置ElasticSearch Head插件
Interesting things What did you do today 先入为主 ElasticSearch Head是什么? ElasticSearch Head是集群管理、数据可视化、
用户2032165
2018/06/06
1.7K0
死磕ES之Windows下环境搭建
ES是一个基于Lucene的分布式全文搜索服务器,和SQL Server的全文索引(Fulltext Index)有点类似,都是基于分词和分段的全文搜索引擎,具有分词,同义词,词干查询的功能,但是ES天生具有分布式和实时的属性。
你呀不牛
2021/05/28
7570
ElasticSearch 6.x head插件安装
ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作。
py3study
2020/02/20
6090
Elasticsearch-02CentOS7安装elasticsearch-head插件
elasticsearch-head是一个界面化的集群操作和管理工具,使用JavaScript开发,依赖Node.js库,使用Grunt工具构建,所以需要先安装Node.js
小小工匠
2021/08/17
4360
ElasticSearch 6.x 学习笔记:2.head与Kibana安装
程裕强
2018/01/02
1.7K0
ES Head插件安装
地址:https://github.com/mobz/elasticsearch-head
郑小超.
2022/09/08
6080
ES Head插件安装
Windows系统下Elasticsearch-7.15.2安装
本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/207
joshua317
2021/12/09
1.2K0
Windows系统下Elasticsearch-7.15.2安装
Elasticsearch极速入门
解压进入bin,执行elasticsearch.bat,启动 端口 9300 程序交互 端口 9200 客户端交互 localhst:9200 看到信息:
青山师
2023/05/05
4710
Elasticsearch极速入门
ES开发指南|如何快速上手ElasticSearch
ElasticSearch不只是全文检索引擎的领头羊,现在也是各个大厂标配的大数据平台之一,被广泛用于搜索加速,用户标签、画像系统、向量搜索等领域,它不是传统的关系型数据库,但这个信息爆炸,数据堆积的时代,我们获取知识的方式已经极大的改变,搜索、提问成了获取知识的第一手段。对ElasticSearch工程师的要求已经不亚于甚至超过了对DBA的要求。那么,要如何才能成为一个被认可的ElasticSearch工程师?希望这篇文章能够从一个开发工程师的角度,给大家带来帮助。
故里
2020/11/25
8740
ES开发指南|如何快速上手ElasticSearch
推荐阅读
相关推荐
windows下安装ElasticSearch的Head插件
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验