![](/img/trans.png)
[英]Shiny R - ggplotly - Show custom message instead of empty plot when the dataset does not return any information
[英]R shiny replace empty plot with message
我有帶有線圖的儀表板。 當應用了過濾器並且數據為空時,我們會看到沒有任何線條的空圖。 我想顯示沒有可用數據的文本消息,而不是空圖。
我看到了 python 的解決方案,但我找不到 R ( link ) 的解決方案。 當沒有要繪制的數據時,我將如何顯示文本消息?
plot_ly(
data = temp,
y = ~value,
x = ~Year_month,
color = ~line_name
) %>%
add_lines() %>%
layout(
yaxis = list(
tickformat = "%",
title = ""
),
xaxis = list(title = ""),
legend = list(
orientation = "h", yanchor = "bottom", y = -1,
font = list(size = 10)
)
)
也許你可以用這個
if (is.null(temp)) {
df <- data.frame()
p <- ggplot(df) + geom_point() + xlim(0, 10) + ylim(0, 10) +
annotate("text", x=3.9, y=5.0, size=40, col="red", label="(" ) +
annotate("text", x=5, y=5.6, size=12, col="red", label="o o" ) +
annotate("text", x=6.1, y=5.0, size=40, col="red", label=")" ) +
annotate("text", x=5, y=5.1, size=12, col="red", label="|" ) +
geom_segment(aes(x = 4.7, xend = 5.3, y = 4.4, yend = 4.4), size=2, color="red") +
annotate("text", x=5, y=3, size=8, col="red", label="No Data")
ggplotly(p)
}else{ ### your plotly code below
plot_ly(...)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.