我试图在数据可用时显示一个图表和标题为"Graph Not available“的临时图表,但无法正常工作。我在这里读到了一个帖子,上面有关于居中标题的空图的有用信息,但在闪亮的应用中解决不了这个问题。有什么想法吗?提前感谢!
以下是我试图在shiny服务器中使用的代码。
observeEvent(input$selected_city, {
if(input$selected_city %in% scenario$place)
{
output$Scenario <-
renderPlotly({
legendtitle <- list(text=paste0("<b>City: ",test_sc()$place),font=list(size=11,
test_sc <- plot_ly(test_sc(), width=700,height=550)
test_sc <- add_lines(test_sc,x=~date,y=~incc,color=I('blue'),name='actual',showlegend=F)
})
}
else{
output$Scenario <-
renderPlotly({
p <- plotly_empty(test_sc(),type = "scatter", mode = "markers") %>%
layout(title = list(
text = 'Sorry! The graph is not available for this city!',
yref = "paper",
xref= "paper",
x = 0.5,
y = 0.5
)
)
return(p)
})
}
发布于 2020-07-13 16:47:22
当绘图不可用时,您可以使用validate
在UI
中输出警告消息,而不是在plotly
中处理警告消息:
observeEvent(input$selected_city, {
output$Scenario <-
renderPlotly({
validate(need(input$selected_city %in% scenario$place, "Sorry! The graph is not available for this city!"))
... # the plotly code
})
})
https://stackoverflow.com/questions/62880148
复制相似问题