cpeikert
cpeikert

Reputation: 31

HTMLWidget: Shiny app run well in Rstudio but Not on Shiny-Server

Recently I have written a html widget to use a javascript file for venn diagram plotting. In RStudio the app works fine so I didn’t realize so far that there is an issue using the app on the shiny server.

If I run the app in with Shiny in RStudio no error is throw and the Web browser shows all other elements of my Shiny page except the new widget. Considering the developer console of the browser I see the following error which is kind of cryptically for me.

Uncaught TypeError: Cannot read property 'filter' of undefined
at exports.OutputBinding.shinyBinding.find (htmlwidgets.js:475)
at a (shiny.min.js:3)
at f (shiny.min.js:3)
at initShiny (shiny.min.js:3)

I also run it outside of RStudio just to get sure but same error.

I have tested this with 2 independent packages so its seems to be a systematical error on my side.

By inspecting the running app in the browser I saw that the following div is created. However, I couldn’t find the submitted data.

<div id="vennDia" style="width:100%; height:400px; " class="vennConductor html-widget html-widget-output"></div>

vennConductor.js:

HTMLWidgets.widget({
  name: 'vennConductor',
  type: 'output',

 initialize: function(el, width, height) {
    },
    renderValue: function(el, x, instance) {
        // console.log(x)
        $(el).jvenn(x)},
    resize: function(el, width, height, instance) {
        $(el).attr("width", width).attr("height", height)
    }
});

In my opinion “relevant” HTMLWidget R code:

htmlwidgets::createWidget(
    name = 'vennConductor',
    json_payload,
    width = width,
    height = height,
    package = 'vennConductor',
    elementId = elementId,
    sizingPolicy = htmlwidgets::sizingPolicy(
      browser.fill = TRUE,
      viewer.fill = TRUE
    )
  )


#' @name vennConductor-shiny
#' @export
vennConductorOutput <- function(outputId, width = '100%', height = '400px'){
  htmlwidgets::shinyWidgetOutput(outputId, 'vennConductor', width, height, package = 'vennConductor')
}

#' @rdname vennConductor-shiny
#' @export
renderVennConductor <- function(expr, env = parent.frame(), quoted = FALSE) {
  if (!quoted) { expr <- substitute(expr) } # force quoted
  htmlwidgets::shinyRenderWidget(expr, vennConductorOutput, env, quoted = TRUE)
}

and the widget call:

jVennConductor(elementId = 'vennDia', venn_lists = vlist_01, displayMode=T, displayStat=T)

Hope anyone can help me out. Thanks!!!

P.s.: R and a Packages are up-to-date and my OS is WINDOWS 10.

Upvotes: 0

Views: 1171

Answers (1)

cpeikert
cpeikert

Reputation: 31

We have found the reason for the problem. Shiny imports jquery by lowercase, jVennConductor by uppercase and that is what causes the error. Simple change both to lowercase solved the problem.

Thanks to Joe Cheng

https://github.com/ramnathv/htmlwidgets/issues/253

Upvotes: 2

Related Questions