【发布时间】:2021-12-02 09:43:32
【问题描述】:
我想做一个错误处理,当有数据时显示绘图图表,当数据为空时,只显示一个白色图表,而不是在 UI 上显示错误。这是我从原始代码中提取的代码。运行app.R后,数据为null时UI会报错。
我也使用了try catch函数尝试删除错误但失败了。任何建议将不胜感激。
# Define UI for app that draws a histogram ----
library(ggplot2)
library(stringr)
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!"),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotlyOutput("toolbar")
)
)
server <- function(input, output) {
data == data.frame()
if (!is.na(data)){
print("no tool_install info!!")
proc_bars <- reactiveValues(plot = NULL)
print(proc_bars)
output$toolbar <- renderPlotly({
tryCatch(
expr = {print(plotly::ggplotly(proc_bars$plot))},
error = function(e){""}
)
})
}}
shinyApp(ui, server)
【问题讨论】: