【发布时间】:2021-06-15 00:54:22
【问题描述】:
我有一个应用程序,当用户在选项卡 1 中选择输入后,该应用程序会将用户重定向到选项卡 2,其中会根据选项卡 1 中选择的输入生成绘图。我添加了 suspendWhenHidden = FALSE 以便该图将在用户重定向到选项卡 2 之前生成。但是,当我添加以下代码行 outputOptions(output, "mtcarsplot", suspendWhenHidden = FALSE) 时,控制台会显示警告。
谁能解释/解决代码中的错误?谢谢您的帮助。我已经添加了代码,然后是下面的警告消息。
应用代码 (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)
警告信息:
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
【问题讨论】: