R svgPanZoom within shinyApp display different in

2019-05-20 08:08发布

I draw a picture using R with packages svgPanZoom,svglite,ggplot2 and shiny. However, it can display correctly on Rstudio but not on Web. Are there any options to solve it? Please run the following code for detail.

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

data<-data.frame(x=1:50,y=1:50)
x_position<-1:50
y_position<-1:50
ui <- pageWithSidebar(
  headerPanel(""),
  sidebarPanel(),
  mainPanel(

    column(width=12,svgPanZoomOutput(outputId = "main_plot",width=600,height=450))

))

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

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

shinyApp(ui,server)

R studio: enter image description here

Web: enter image description here

2条回答
欢心
2楼-- · 2019-05-20 08:54

I had a similar problem, and fixed it very easily. Here are the snippets from ui.R:

svgPanZoomOutput(outputId = "betaPlot", height = "800px")

and server.R

p = ggplot(blah blah)

    svgPanZoom(
  svglite::stringSVG(print(p), standalone = F),
  controlIconsEnabled = T, viewBox = FALSE
)

It's the viewBox = FALSE that you need for an external browser, and you need to adjust the height of the graph in ui.R otherwise the controls don't show.

Load library(svglite) and library(svgPanZoom), obviously

Well, it worked for me anyway

查看更多
倾城 Initia
3楼-- · 2019-05-20 08:58

Finally, I try the package "SVGAnnotation" and fortunately solved the problem.

查看更多
登录 后发表回答