当所需数据为空时,如何打印自定义警告/错误消息?
例如,在我的 server.R 中,我有下面的代码,
output$plot = renderPlot({
# Sites.
site1 = input$site1
# Prepare SQL query.
query <- "SELECT * FROM datatable
WHERE sites.id = 'SITE1'
"
# Match the pattern and replace it.
query <- sub("SITE1", as.character(site1), query)
# Store the result in data.
data = dbGetQuery(DB, query)
if (is.na(data) || data == '') {
# print error/ warning message
"sorry, no data is found."
} else {
# plot the data
dens <- density(data$particles, na.rm = …Run Code Online (Sandbox Code Playgroud)