简体   繁体   English

HTMLWidget:Shiny应用在Rstudio中运行良好,但在Shiny-Server上却无法运行

[英]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. 最近,我编写了一个html小部件,以使用javascript文件进行维恩图绘制。 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. 在RStudio中,该应用程序运行良好,因此到目前为止,我还没有意识到在闪亮的服务器上使用该应用程序会出现问题。

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. 如果我在RStudio中使用Shiny运行应用程序,则不会引发任何错误,并且Web浏览器将显示Shiny页面中除新窗口小部件之外的所有其他元素。 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. 我也在RStudio之外运行它,只是为了确定但还是相同的错误。

I have tested this with 2 independent packages so its seems to be a systematical error on my side. 我已经使用2个独立的程序包对此进行了测试,因此对我来说,这似乎是系统的错误。

By inspecting the running app in the browser I saw that the following div is created. 通过检查浏览器中正在运行的应用程序,我看到创建了以下div。 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: 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: 我认为“相关的” HTMLWidget R代码是:

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!!! 谢谢!!!

Ps: R and a Packages are up-to-date and my OS is WINDOWS 10. 附言:R和a软件包是最新的,我的操作系统是WINDOWS 10。

We have found the reason for the problem. 我们已经找到了问题的原因。 Shiny imports jquery by lowercase, jVennConductor by uppercase and that is what causes the error. Shiny按小写导入jquery,按大写导入jVennConductor,这就是导致错误的原因。 Simple change both to lowercase solved the problem. 只需将其更改为小写即可解决问题。

Thanks to Joe Cheng 多亏郑Cheng

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM