0

根据帖子How to display scatter plot with R Packages:svgPanZoom? 我试图在 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)
4

1 回答 1

1
  1. svgPanZoomOutput您的 UI 中缺少将 svgpanzoom 绑定到闪亮
  2. 你已经svgPanZoom在只属于renderSvgPanZoom服务器的 UI 中使用过
  3. 它以任何一种方式工作 - 使用这个解决方案或只是来自的基本示例?svgPanZoom
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)
于 2020-12-09T16:03:37.830 回答