svglite,svgPanZoom 无法在 R shiny 中绘制

svglite, svgPanZoom not able to plot in R shiny

根据 post 我试图在 R shiny 中复制一个可缩放的图。有人可以帮我处理我的代码吗?为什么我不能重现此代码?

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


# Define UI ----
ui <- shinyUI(bootstrapPage(
    # App title ----
  headerPanel("Cyl vtree"),
  
    
 # Main panel for displaying outputs ----
  svgPanZoom(
    svglite:::inlineSVG(
      show(p)
    ),
    controlIconsEnabled = T
  )
  
))

# Define server logic to plot ----
server <- function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()
    svgPanZoom(p, controlIconsEnabled = T)
  })
}

shinyApp(ui, server)
  1. svgPanZoomOutput 在您的 UI 中丢失,无法将 svgpanzoom 绑定到 shiny
  2. 您在UI中使用了svgPanZoom,它只属于服务器
  3. 中的renderSvgPanZoom
  4. 它以任何一种方式工作 - 使用 或仅使用 ?svgPanZoom
  5. 中的基本示例
library(shiny)
library(svglite)
library(svgPanZoom)
library(ggplot2)
library(gridSVG)

# Define UI ----
ui <- shinyUI(bootstrapPage(
  # App title ----
  headerPanel("Cyl vtree"),
  
  
  # Main panel for displaying outputs ----
  svgPanZoomOutput(outputId = "main_plot")
  
  
))

# Define server logic to plot ----
server <- function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()

    svgPanZoom(p, controlIconsEnabled = T)
  })
}

shinyApp(ui, server)