【问题标题】:R shiny replace empty plot with messageR闪亮用消息替换空图
【发布时间】:2021-10-02 18:24:49
【问题描述】:

我有带线图的仪表板。当应用了过滤器并且数据为空时,我们会看到没有任何线条的空图。我想显示没有可用数据的文本消息,而不是空图。

我看到了 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)
                )
            )

【问题讨论】:

    标签: r shiny plotly


    【解决方案1】:

    也许你可以用这个

    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(...)
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2017-11-05
    • 2015-01-11
    • 2019-03-07
    • 2021-08-16
    相关资源
    最近更新 更多