Reputation: 11
does anyone know if it is possible to display a text in renderPlotly instead error message when the dataset is empty? I tried print for the time being, but it didnt work.
if (nrow(result) == 0){
print("Sorry, ther is no such flat type in the select town")
}
else{
p<-ggplot(result, (aes(year,total_price,colour = town)))
p <- p + geom_line() +
ggtitle("Total Resale Price By Town") +
labs(x = "Year", y = "Total Resale Price ($)")+
scale_y_continuous(labels = dollar) +
theme(plot.title = element_text(size = 12,hjust = 0.5))
# without tooltip settings, "town" appears twice...
p <- ggplotly(p, tooltip = c("x","y","colour"))
p
}
Upvotes: 0
Views: 149
Reputation: 84529
You can use validate
:
output$plot <- renderPlotly({
validate(
need(nrow(result) != 0, 'Sorry, the dataset is empty')
)
p <- ggplot(......) + ......
ggplotly(p)
})
Upvotes: 2