如何在Rshiny应用程序中播放本地视频?
我试图让本地保存的视频在 RShiny 中播放,但我只得到一个空的视频播放器,没有加载视频或加载视频的方法。我在搜索时看到了几篇关于此问题的帖子,但似乎没有一个找到答案。我的代码是:
library(shiny)
ui <- fluidPage(
tags$video(src = "C:/Downloads/big_buck_bunny_720p_30mb.mp4", type
= "video/mp4", autoplay = TRUE, controls = TRUE)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
这会导致在 RStudio 浏览器或 Edge 中加载迷你播放器,但没有视频:
但是,如果我在 Edge 页面上查看源代码,将其另存为 .html 文件并在 Edge 中加载该文件,则效果很好。从 RStudio 运行时它不起作用,因为当地址格式为 http: 时,Edge 不会显示视频: //127.0.0.1:6190/。有什么想法吗?安全设置什么的?如果我使用 Web URL 而不是本地视频文件,RStudio 也能正常播放相同的视频。
我已经尝试了 ui.r / server.r、www 文件夹中的文件等的大量迭代,但都不起作用。 Rstudio 本机浏览器与 Edge 具有相同的行为(尽管它也无法显示 .html 文件)。
谢谢@ismirsehregal - 这让我走得更远。视频现在可以播放,但奇怪的是看起来已经褪色(变灰)了。如果我选择全屏,颜色会完全恢复。实际视频为 https://sample-videos.com/video123/mp4/ 720/big_buck_bunny_720p_30mb.mp4 如果有帮助的话。
在 RStudio 中,我还收到消息:
Listening on http://127.0.0.1:7109 警告:值 [[3L]] 中出现错误:无法规范化 addResourcePath
中的路径,参数为:prefix
= 'videos'; directoryPath
= 'C:/下载' 55:停止 54:值[[3L]] 53: 尝试捕获一个 52: 尝试捕获列表 51: 尝试捕获 50: 添加资源路径 49:服务器[#2] 值错误[3L]: 无法规范化 addResourcePath
中的路径,参数为:prefix
= 'videos'; directoryPath
= 'C:/Downloads'
但除了它的工作颜色之外。
I'm trying to get videos saved locally to play in RShiny but I only get an empty video player with no video loaded or way to load one. I've seen several posts on this when searched but none seem to reach an answer. My code is:
library(shiny)
ui <- fluidPage(
tags$video(src = "C:/Downloads/big_buck_bunny_720p_30mb.mp4", type
= "video/mp4", autoplay = TRUE, controls = TRUE)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
This results in a mini player loading in RStudio browser or Edge but no video:
However, if I view source on the Edge page, save that as an .html file and load that file in Edge it works fine. It just doesn't work when run from RStudio as in Edge won't display videos when the address is of the form http://127.0.0.1:6190/. Any ideas? Security settings or something? RStudio plays the same video fine if I instead use a web URL rather than local video file as well.
I've tried loads of iterations of ui.r / server.r, files in www folder, etc. none of which work. Rstudio native browser has same behaviour as Edge (although it can't display the .html file either).
Thanks @ismirsehregal - this gets me a lot further. The video now plays but weirdly looks washed (greyed) out. If I select fullscreen the colour comes back fully. The actual video is https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_30mb.mp4 if that helps.
In RStudio I also get the message:
Listening on http://127.0.0.1:7109
Warning: Error in value[[3L]]: Couldn't normalize path in addResourcePath
, with arguments: prefix
= 'videos'; directoryPath
= 'C:/Downloads'
55: stop
54: value[[3L]]
53: tryCatchOne
52: tryCatchList
51: tryCatch
50: addResourcePath
49: server [#2]
Error in value[3L] :
Couldn't normalize path in addResourcePath
, with arguments: prefix
= 'videos'; directoryPath
= 'C:/Downloads'
but apart from the colour it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
addResourcePath
向Shiny的Web服务器添加静态资源。请尝试以下内容:
但是,使用
www
子目录也应该很好。www
文件夹的前缀是“/”。请参阅 this 。You can add static resources to Shiny's web server via
addResourcePath
.Please try the following:
However, using the
www
subdirectory should also be fine. The prefix for thewww
folder is "/". Please see this.