简体   繁体   English

添加suspendWhenHidden时,quartz()设备大小无效

[英]invalid quartz() device size when suspendWhenHidden is added

I have an app such that after a user has selected input in tab 1, the app will redirect the user to tab 2, where a plot is generated based on the input selected in tab 1. I added suspendWhenHidden = FALSE so that the plot will be generated before the user is redirected to tab 2. However, when I added the following line of code, outputOptions(output, "mtcarsplot", suspendWhenHidden = FALSE) , the console shows a warning.我有一个应用程序,当用户在选项卡 1 中选择输入后,该应用程序会将用户重定向到选项卡 2,其中基于选项卡 1 中选择的输入生成 plot。我添加了suspendWhenHidden = FALSE以便 plot 将在用户被重定向到选项卡 2 之前生成。但是,当我添加以下代码行outputOptions(output, "mtcarsplot", suspendWhenHidden = FALSE)时,控制台会显示警告。

Can anyone explain/solve the error in the code?谁能解释/解决代码中的错误? Thanks for the help.谢谢您的帮助。 I have added the code and then the warning message below.我已经添加了代码,然后是下面的警告消息。

the app's code (MWE):应用程序代码(MWE):

data(mtcars)

ui <- fluidPage(
  navbarPage(title = "Plotting", id = "mtcars",
             tabPanel(title = "home",
                      selectInput(inputId = "col", label = "Choose a column", choices = names(mtcars)),
                      actionButton(inputId = "update", label = "Update")
             ),
             tabPanel(title = "plot",
                      plotOutput("mtcarsplot"), 
                      actionButton(inputId = "back", label = "Back")
             ))
)

server <- function(input, output, session) {
  observeEvent(input$update, {
    updateTabsetPanel(session = session, inputId = "mtcars", selected = "plot")
  })
  
  col <- eventReactive(input$update, {
    input$col
  })
  
  observeEvent(input$back, {
    updateTabsetPanel(session = session, inputId = "mtcars", selected = "home")
  })
  
  mtcars_new <- reactive({
    mtcars %>%
      select(mpg, userscol = col())
  })
  
  mtcars_plot <- reactive({
    ggplot(data = mtcars_new(), aes(x = mpg, y = userscol)) +
      geom_point()
  })
  
  output$mtcarsplot <- renderPlot({mtcars_plot()})
  outputOptions(output, "mtcarsplot", suspendWhenHidden = FALSE)
}


shinyApp(ui = ui, server = server)

The Warning message:警告信息:

Warning: Error in <Anonymous>: invalid quartz() device size
  128: <Anonymous>
  126: startPNG
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: renderFunc
   81: output$mtcarsplot
    1: runApp

The documentation states该文件指出

文档

You are bound to see the error, if you set suspendWhenHidden = FALSE, as the output object is not available yet until you click on update button.如果您设置 suspendWhenHidden = FALSE,您一定会看到错误,因为 output object 在您单击更新按钮之前尚不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM