简体   繁体   English

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

[英]ggiraph plot not appearing in shiny app, but works in RStudio

I really want to use ggiraph to add tooltips in my shiny app.我真的很想使用ggiraph在我shiny应用程序中添加工具提示。 However, when I try to do so the plot does not appear.但是,当我尝试这样做时,情节不会出现。 In the example below I used a plotOutput and ggiraphOutput but only my.plot appears.在下面的示例中,我使用了plotOutputggiraphOutput但只出现了my.plot I can produce the interactive plots in RStudio, just not within the app.我可以在 RStudio 中生成交互式绘图,而不是在应用程序中。 Is there something wrong with my implementation?我的实现有问题吗? Or could there be a compatibility issue ( sessionInfo() below)?或者可能存在兼容性问题(下面的sessionInfo() )? Thanks!谢谢!

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)

Here is my sessionInfo()这是我的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   

I'm not 100% sure why, but the problem seems to be with the "."我不是 100% 确定为什么,但问题似乎出在“。” (period) in the outputID name. (句点)在 outputID 名称中。 If you change it to如果你把它改成

ggiraphOutput(outputId = "interactivePlot")

and

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

it seems to work just fine.它似乎工作得很好。 And this does seem to be documented in the ?girafeOutput help page, though not the ?ggiraphOutput help page.这似乎记录在?girafeOutput帮助页面中,尽管不是?ggiraphOutput帮助页面。

output variable to read the girafe from.用于读取长颈鹿的输出变量。 Do not use special JavaScript characters such as a period .不要使用特殊的 JavaScript 字符,例如句点。 in the id, this would create a JavaScript error.在 id 中,这会产生一个 JavaScript 错误。

It seems they are trying to use girafeOutput and renderGirafe going forward.看来他们正在尝试使用girafeOutputrenderGirafe向前发展。

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

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