如何在闪亮的浏览器模式下调试ggplot?

Abh*_*bhi 2 debugging plot ggplot2 shiny

我们曾经使用浏览器检查反应值,但是当 ggplot 未呈现预期图形时,我们如何在反应模式下调试它?

library(shiny)

ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    browser() # Here, the browser stops but when run the below line, cannot see the plot in plots tab
    plot(mtcars$wt, mtcars$mpg) # or ggplot ...both not rendering plot in browser mode
  })

  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

tho*_*hal 6

实际上,您可以请求打开新设备:

Listening on http://127.0.0.1:7460
Called from: renderPlot(...)
Browse[1]> plot(mtcars$wt, mtcars$mpg) ## won't plot
Browse[1]> dev.new() ## opens a new window
Browse[1]> plot(mtcars$wt, mtcars$mpg) ## now plots
Run Code Online (Sandbox Code Playgroud)