如何用RPackages:svgPanZoom显示散点图?

How to display scatter plot with R Packages:svgPanZoom?

我用ggplot2 画了一张图,想用svgPanZoom 包在shinyApp 中显示它。但是星体消失了。有人知道为什么吗? 您可以运行以下代码了解详情:

library(shiny)
library(svglite)
library(svgPanZoom)
library(ggplot2)

data<-data.frame(x=1:10,y=1:10)

ui <- shinyUI(bootstrapPage(

  svgPanZoomOutput(outputId = "main_plot")

))

server = shinyServer(function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot(data, aes(x = x, y = y)) + geom_point()
    svgPanZoom(p, controlIconsEnabled = T)
  })
})

shinyApp(ui,server)

我相信你还需要添加 svglite

library("svglite")

然后用这个替换 svgPanZoom 调用

svgPanZoom(
      svglite:::inlineSVG(
        show(p)
      ),
   controlIconsEnabled = T
)