Jiajin.Chen
Jiajin.Chen

Reputation: 93

How to display scatter plot with R Packages:svgPanZoom?

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)

Upvotes: 0

Views: 119

Answers (1)

penguin
penguin

Reputation: 1376

I believe you need to add svglite also

library("svglite")

Then replace svgPanZoom call with this

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

Upvotes: 1

Related Questions