ggiraph 图没有出现在闪亮的应用程序中,但在 RStudio 中有效

ggiraph plot not appearing in shiny app, but works in RStudio

我真的很想使用 ggiraph 在我的 shiny 应用程序中添加工具提示。但是,当我尝试这样做时,情节不会出现。在下面的示例中,我使用了 plotOutputggiraphOutput,但只出现了 my.plot。我可以在 RStudio 中生成交互式图表,只是不在应用程序中。我的实施有问题吗?或者可能存在兼容性问题(下面的 sessionInfo())?谢谢!

library(ggiraph)
library(shiny)
library(ggplot2)
ui <- fluidPage(
  fluidRow(
    column(6,plotOutput(outputId ="my.plot")),
    column(6,ggiraphOutput(outputId = "interactive.plot"))
  )
)

server <- function(input, output){
  output$my.plot <- renderPlot({
    data = data.frame(x = 1:10, y= rnorm(10), z = 11:20)
    ggplot(data, aes(x = x, y = y)) + geom_col()

    #girafe(ggobj = xx)
  })
  output$interactive.plot <- renderggiraph({
    data = data.frame(x = 1:10, y= rnorm(10), z = 11:20)
    gg <- ggplot(data, aes(x = 1:10, y = rnorm(10), z = 11:20)) + geom_col_interactive(aes(tooltip = z))
    girafe(ggobj = gg)
  })
}

shinyApp(ui, server)

这是我的 sessionInfo()

R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gdtools_0.2.1 ggplot2_3.2.1 shiny_1.4.0   dplyr_0.8.4   ggiraph_0.7.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.0.0  remotes_2.1.0     purrr_0.3.3       colorspace_1.4-1  testthat_2.3.1    htmltools_0.4.0   usethis_1.5.1    
 [8] yaml_2.2.1        rlang_0.4.4       pkgbuild_1.0.6    pillar_1.4.3      later_1.0.0       glue_1.3.1        withr_2.1.2      
[15] sessioninfo_1.1.1 uuid_0.1-4        lifecycle_0.1.0   munsell_0.5.0     gtable_0.3.0      devtools_2.2.1    htmlwidgets_1.5.1
[22] memoise_1.1.0     labeling_0.3      callr_3.4.1       fastmap_1.0.1     Cairo_1.5-11      httpuv_1.5.2      ps_1.3.0         
[29] fansi_0.4.1       Rcpp_1.0.3        xtable_1.8-4      scales_1.1.0      backports_1.1.5   promises_1.1.0    desc_1.2.0       
[36] pkgload_1.0.2     jsonlite_1.6.1    farver_2.0.3      mime_0.9          systemfonts_0.1.1 fs_1.3.1          digest_0.6.23    
[43] processx_3.4.2    cowplot_1.0.0     grid_3.5.3        rprojroot_1.3-2   cli_2.0.1         tools_3.5.3       magrittr_1.5     
[50] lazyeval_0.2.2    tibble_2.1.3      crayon_1.3.4      pkgconfig_2.0.3   ellipsis_0.3.0    xml2_1.2.2        prettyunits_1.1.1
[57] assertthat_0.2.1  rstudioapi_0.11   R6_2.4.1          compiler_3.5.3   

我不是 100% 确定原因,但问题似乎出在“.”上。 (句点)在 outputID 名称中。如果你把它改成

ggiraphOutput(outputId = "interactivePlot")

output$interactivePlot <- renderggiraph({ ... ])

它似乎工作得很好。这似乎确实记录在 ?girafeOutput 帮助页面中,尽管 ?ggiraphOutput 帮助页面中没有。

output variable to read the girafe from. Do not use special JavaScript characters such as a period . in the id, this would create a JavaScript error.

他们似乎正在尝试使用 girafeOutputrenderGirafe 向前发展。