5

I really want to use ggiraph to add tooltips in my shiny app. 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. I can produce the interactive plots in RStudio, just not within the app. Is there something wrong with my implementation? Or could there be a compatibility issue (sessionInfo() below)? 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()

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   
4

1 回答 1

6

我不是 100% 确定为什么,但问题似乎与“。”有关。(句点)在 outputID 名称中。如果您将其更改为

ggiraphOutput(outputId = "interactivePlot")

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

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

从中读取长颈鹿的输出变量。不要使用特殊的 JavaScript 字符,例如句点。在 id 中,这将创建一个 JavaScript 错误。

似乎他们正在尝试使用girafeOutputrenderGirafe继续前进。

于 2020-03-30T21:11:09.693 回答