r - 创建一个带有标题的空 Plotly 图在 R 闪亮的应用程序中不显示标题但完全空白
问题描述
我试图在数据可用时显示一个图表,并且标题为“图表不可用”的临时图表,但无法正常工作。我在这里阅读了一个线程,其中包含有关标题居中的空图的有用信息,但无法解决闪亮应用程序中的问题。有什么想法吗?提前致谢!
这是我试图在闪亮服务器中使用的代码。
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)
})
}
解决方案
plotly
您可以使用在绘图不可用时validate
输出警告消息,而不是在内部处理警告消息:UI
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
})
})
推荐阅读
- python - Windows 上的 Python 可执行权限
- matlab - 将图形转换为 2D 图表
- django - Django - 导入导出 - 上传多个文件
- c# - 当 Window 具有带有 TabItem 的 TabControl 时的 C# WPF 内存泄漏(或延迟内存回收?)
- wordpress - 从 WooCommerce 中的 URL 中删除 /product-category/ 和 /shop/
- sql - 存储过程和数据导出自动化
- node.js - 生产环境中 node.js 应用程序中 connect.sid 和会话的问题
- azure - 自定义视觉保存当前模型
- python - 如何在 url 中获取项目搜索显示的名称
- pytorch - 如何在 pipenv 中指定 pytorch / cuda 版本