R 在闪亮的web应用程序中显示错误而不是绘图

R 在闪亮的web应用程序中显示错误而不是绘图,r,shiny,R,Shiny,我有一个有很多情节的闪亮网络应用程序。每个绘图都有自己的SQL查询来获取数据。其中一个查询可能返回数据不足的表。如果发生这种情况,那么我想在绘图的选项卡中显示一条文本消息 服务器.R: library(shiny) library(RMySQL) shinyServer(function(input, output, session) { output$lineGraphOne <- renderPlot({ table <- getDataSomeHo

我有一个有很多情节的闪亮网络应用程序。每个绘图都有自己的SQL查询来获取数据。其中一个查询可能返回数据不足的表。如果发生这种情况,那么我想在绘图的选项卡中显示一条文本消息

服务器.R:

library(shiny)
library(RMySQL)

shinyServer(function(input, output, session) {

    output$lineGraphOne <- renderPlot({

        table <- getDataSomeHowOne()

        if(dim(table[1]) < 3) {            
            error <- paste("Some error message")            
        } else {            
            plot(x = as.Date(table$date), y = table$count)            
        }
    })

    output$lineGraphTwo <- renderPlot({

        table <- getDataSomeHowTwo()

        if(dim(table[1]) < 3) {            
            error <- paste("Some error message")            
        } else {            
            plot(x = as.Date(table$date), y = table$count)            
        }

    })    
})

如何实现在相应选项卡中显示错误字符串而不是绘图?

请查看
验证
,注意示例取自

rm(list=ls())
图书馆(闪亮)
runApp(列表(
ui=(fluidPage)(
titlePanel(“验证应用程序”),
侧边栏布局(
侧栏面板(
选择输入(“数据”,label=“数据集”,
选项=c(“,”mtcars“,”忠实“,”虹膜“)
),
#显示生成的分布图
主面板(
表格输出(“表格”),
绘图输出(“绘图”)
)
)
)),
服务器=功能(输入、输出){

请看一下验证数据,谢谢!我怎么会错过这一点。
library(shiny)

shinyUI(navbarPage("Title",                   
    tabPanel("Name",                            
        sidebarLayout(            
            mainPanel(
                tabsetPanel(id = "tabs",
                    tabPanel("One", plotOutput("lineGraphOne")),
                    tabPanel("Two", plotOutput("lineGraphTwo"))
                )
            ),            
            sidebarPanel(
                dateInput('queryDate', 'Datum:', value = as.Date("2010-04-09"))
            )
        )            
    )                   
))
rm(list = ls())
library(shiny)
runApp(list(
  ui = (fluidPage(

    titlePanel("Validation App"),

    sidebarLayout(
      sidebarPanel(
        selectInput("data", label = "Data set",
                    choices = c("", "mtcars", "faithful", "iris"))
      ),

      # Show a plot of the generated distribution
      mainPanel(
        tableOutput("table"),
        plotOutput("plot")
      )
    )
  )),
  server = function(input, output) {

    data <- reactive({ 
      validate(
        need(input$data != "", "Please select a data set")
      )
      get(input$data, 'package:datasets') 
    })

    output$plot <- renderPlot({
      hist(data()[, 1], col = 'forestgreen', border = 'white')
    })

    output$table <- renderTable({
      head(data())
    })

  }
))