How to display scatter plot with R Packages:svgPanZoom?

荒凉一梦 提交于 2021-02-08 10:40:26

问题


I draw a picture using ggplot2 and want to display it in shinyApp with svgPanZoom packages. But the sactters is disappear. Anybody know why? You can run the following code for detail:

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)

回答1:


I believe you need to add svglite also

library("svglite")

Then replace svgPanZoom call with this

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


来源:https://stackoverflow.com/questions/50055111/how-to-display-scatter-plot-with-r-packagessvgpanzoom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!