r - 闪亮的应用程序:`shinyjs`解析错误,但脚本作为`script`标签工作
问题描述
我用视频流制作了一个简单的 Shiny 应用程序(如果可以,使用笔记本电脑的摄像头)。整个Javascript是:
const player = document.getElementById('player');
const constraints = {
video: true
};
// Attach the video stream to the video element and autoplay.
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
player.srcObject = stream;
});
如果我把它包装在这样一个闪亮的应用程序中,
ui <- fluidPage(
HTML('<video id="player" controls autoplay></video>'),
tags$script(HTML(<<<CODE ABOVE>>>))
)
server <- function(input,output){}
shinyApp(ui,server)
它工作正常。
相反,如果我使用该shinyjs
包,请将 Javascript 放在它自己的文件“startvid.js”中,并制作如下应用程序:
ui <- fluidPage(
HTML('<video id="player" controls autoplay></video>'),
useShinyjs(),
extendShinyjs(script = "www/startvid.js")
)
解析时出现语法错误:
Error: shinyjs: Error parsing the JavaScript file: SyntaxError: Unexpected token >.
这里发生了什么?
解决方案
我注意到你=>
在代码中,我认为这可能是原因。
对我来说更换线路
var vector_out_it = Array.from(table_data, x => x[0]);
有线条
var vector_out_it = [];
for(it = 0; it < table_data.length; it ++) {vector_out_it.push(table_data[it][0])}
解决了问题
PS 出于某种原因,我的闪亮服务器在使用 js 胖数组运算符时遇到了困难(有关说明,请参阅 https://www.sitepoint.com/es6-arrow-functions-new-fat-concise-syntax-javascript/)
它可能取决于系统配置,因为对我来说extendShinyjs
在本地运行良好(仅在应用程序部署后,我收到您描述的错误:
Warning: Error in : shinyjs: Error parsing the JavaScript file: SyntaxError: Unexpected token >.
推荐阅读
- python - 如何在 Django 中读取 pdf 文件
- c# - 解析值 + 删除垃圾
- laravel - 如何让 IDE 识别 Laravel Routes 使用的方法?(PHP风暴)
- node.js - 带有节点 js 和 ES 模块的打字稿非相对导入不起作用
- python - 我应该使用哪个来构建带有 matplotlib 绘图的简单 GUI?
- python-3.x - 如何使用多个函数创建多个数据框
- python - 检测熊猫数据框列中的时间差是否为负
- powershell - Powershell 重命名和压缩文件
- javascript - 如何在守夜人的块之间传递页面对象实例?
- java - Android,Java,从服务中监听 KEYCODE_MEDIA_PLAY_PAUSE?