作者: 李誉辉
四川大学在读研究生
前言
这是 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)
浏览器运行结果如下:
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))
运行结果如下:
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结构
-
Shiny中文教程
-
Shiny小元素
https://sh iny.rstudio.com/tutorial/written-tutorial/lesson2/
-
所有HTML tags
-
一张图学会shiny
-
html教程
-
html支持的颜色名称
-
html字体
-
html图片链接
-
shiny中更改字体样式
https://stackoverflow.com/questions/24049159/change-the-color-and-font-of-text-in-shiny-app
-
shiny中插入图片
-
markdown中插入音频
https://www.sunyazhou.com/2017/12/27/20171227markdown-audio/
-
leaflet与shiny结合
-
shiny反应表达式
-
多个提交按钮
https://stackoverflow.com/questions/24220105/can-i-have-multiple-submit-buttons-in-r-shiny
——————————————
往期精彩:
天善智能 每日一道算法题,打卡学习 小程序
本文由R语言中文社区 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
High Performance Python
Micha Gorelick、Ian Ozsvald / O'Reilly Media / 2014-9-10 / USD 39.99
If you're an experienced Python programmer, High Performance Python will guide you through the various routes of code optimization. You'll learn how to use smarter algorithms and leverage peripheral t......一起来看看 《High Performance Python》 这本书的介绍吧!