I'm using MongoDB Stitch within my Shiny application, and to use my query function, I need to import the Stitch export from the MongoDB Stitch JavaScript SDK. The following is parsed with no issues locally using extendShinyjs:
library(shiny)
library(shinyjs)
jsCode <- '
shinyjs.init = function() {
const {
Stitch
} = stitch;
window.stitchClient = Stitch.initializeDefaultAppClient("xxx");
}'
shinyApp(
ui = fluidPage(
tags$head(HTML('<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.9.0/stitch.js"></script>')),
useShinyjs(),
extendShinyjs(text = jsCode)
),
server = function(input, output) {
}
)
However, I get the following error when the above code is called by extendShinyjs in the shiny server: shinyjs: Error parsing the JavaScript code provided. I've confirmed through repeated tests that the issue is through my calling the Stitch export with the first command of the shinyjs.init function. Not sure if there's a work around this. Thanks for your help!
Important detail to note: I am running the shiny-server on a container utilizing the rocker/shiny base image, which as of now, uses a Debian 9 (stretch) base image. According to Jeroen (https://github.com/jeroen/V8/issues/86), the V8 parser that came with Debian 9 is the legacy version and consequently, modern JS was not parsed correctly when I was running the script above. rocker/r-ver now uses Debian 10 (buster), so I used that base image, installed dependencies outlined in the rocker/shiny Dockerfile, and the script runs without a problem. Hopefully the rocker/shiny Dockerfile is updated soon!