闪亮的应用:“ shinyjs”解析错误,但脚本可作为“ script”标签使用

时间:2018-06-20 07:58:40

标签: r shiny shinyjs

我制作了一个带有视频流的简单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 >.

这是怎么回事?

1 个答案:

答案 0 :(得分:0)

我注意到您的代码中有=>,我认为这可能是原因。

对于我来说,替换行

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 >.