shinydashboard与shiny_史上最全(四)

640?wx_fmt=png

作者:李誉辉  

四川大学在读研究生


前言

这是shinydashboard与shiny_史上最全第四篇,也是最后一篇。

前文回顾:

shinydashboard与shiny_史上最全(一) 

shinydashboard与shiny_史上最全(二)

shinydashboard与shiny_史上最全(三)


第一部分: 

  • 1 简介

  • 2 shiny文件的创建和运行

  • 3 shinydashboard

         3.1 标题栏(Header)

       

第二部分

        3.2 输入与输出

        3.3 侧边栏

        3.4 主体(Body)

        3.5 布局(Layouts)

       

第三部分

  • 4 shiny框架

  • 5 选项卡(tabset)

  • 6 美化

  • 7 CSS语法


第四部分

  • 8 与leaflet结合

  • 9 web部署



7.6

插入视频

视频与音频类似,同样需要外链。

UI端代码如下:


 1library(shiny)
2
3shinyUI(fluidPage(
4  mainPanel(
5    strong("Katy Perry MV,框架插入,临时外链,可能失效"),
6    br(),
7    tags$iframe(src = "https://vd.yinyuetai.com/he.yinyuetai.com/uploads/videos/common/EFC90168F02CAF3035BF1A310EBBAD7C.mp4",
8               height = 400, width = 710, scrolling = "no", seamless = FALSE),
9    br(),
10    strong("Katy Perry MV,video函数插入,临时外链,可能失效"),
11    br(),
12    tags$video(src = "https://vd.yinyuetai.com/he.yinyuetai.com/uploads/videos/common/EFC90168F02CAF3035BF1A310EBBAD7C.mp4",
13               type = "video/mp4", autoplay = FALSE, controls = TRUE),
14    br(),
15    strong("Katy Perry MV,框架插入,网盘外链,永久有效"),
16    br(),
17    tags$iframe(src = "https://www.opendrive.com/player/NDVfOTcwMjEwNl9oeFdlbQ",
18                height = 400, width = 710, scrolling = "no", seamless = FALSE)
19
20  )
21)


浏览器运行结果如下:


shinydashboard与shiny_史上最全(四)_第1张图片



7.7

插入列表


 1library(shiny)
2
3shinyUI(fluidPage(
4  mainPanel(
5      tags$ul(
6        tags$li("第1个项目"),
7        tags$li("第2个项目"),
8        tags$li("第3个项目")
9      )
10  )
11))


运行结果如下:
640?wx_fmt=png

8.与leaflet结合

leaflet自带renderLeaflet()leafletOutput()
因为我们还没介绍
leaflet的内容,所以这里不做展开了。有兴趣的可以看文末的参考来源:

9.web部署

通过 shinyapps (https://www.shinyapps.io/)将shiny程序部署到云端,

这样其它人可以通过浏览器访问。 在该网站注册后,会分配令牌号和密码。
然后使用
rsconnect包就可以。 如果要导出html文件的交互式网页,能保存在本地,使用rmarkdown + flexdashboard更加方便。

9.1

登陆云端账户

下面使用使用伪账号及密码进行模拟登陆。


1library(rsconnect) 
2rsconnect::setAccountInfo(name='xxxxxxx'# 账户名
3              token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'# 令牌
4              secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'# 密码


9.2

将Shiny程序部署到云端


1library(shiny)
2
3library(rsconnect)
4rsconnect::deployApp('E:/R_setwd_documents/Shiny_directory/Shiny_test_1')

运行后,会自动打开浏览器,访问云端程序所在的网址。

个人云端网址(https://liyuhui.shinyapps.io/shiny_test_1/
要关闭云端的程序,使用
terminateApp()即可。免费的账户只能支持5个应用程序。

1library(shiny)
2
3setwd("E:/R_setwd_documents/Shiny_directory")
4runApp('Shiny_test_1'


考来源

  • shinydashboard结构

    https://rstudio.github.io/shinydashboard/structure.html

  • Shiny中文教程

    http://yanping.me/shiny-tutorial/#tabsets

  • Shiny小元素

    https://shiny.rstudio.com/tutorial/written-tutorial/lesson2/

  • 所有HTML tags

    https://shiny.rstudio.com/articles/tag-glossary.html

  • 一张图学会shiny

    https://shiny.rstudio.com/images/shiny-cheatsheet.pdf

  • html教程

    https://www.tutorialspoint.com/html/html_fonts.htm

  • html支持的颜色名称

    https://www.tutorialspoint.com/html/html_color_names.htm

  • html字体

    https://www.tutorialspoint.com/html/html_fonts.htm

  • html图片链接

    https://www.tutorialspoint.com/html/html_fonts_ref.htm

  • shiny中更改字体样式

    https://stackoverflow.com/questions/24049159/change-the-color-and-font-of-text-in-shiny-app

  • shiny中插入图片

    https://shiny.rstudio.com/articles/images.html

  • markdown中插入音频

    https://www.sunyazhou.com/2017/12/27/20171227markdown-audio/

  • leaflet与shiny结合

    https://rstudio.github.io/leaflet/shiny.html

  • shiny反应表达式

    http://shiny.rstudio.com/articles/action-buttons.html

  • 多个提交按钮

    https://stackoverflow.com/questions/24220105/can-i-have-multiple-submit-buttons-in-r-shiny

——————————————

往期精彩:

  • IT男,程序猿在婚恋市场有多受欢迎?

  • 都挺好,怎么好?

  • 史上最污技术解读,让你秒懂IT术语

  • R语言中文社区2018年终文章整理(作者篇)

  • R语言中文社区2018年终文章整理(类型篇)

640?wx_fmt=png

你可能感兴趣的:(shinydashboard与shiny_史上最全(四))