【问题标题】:Shiny: xts plot (xtsExtra) disappears when checkbox unchecked闪亮:未选中复选框时,xts 图(xtsExtra)消失
【发布时间】:2015-01-28 14:52:01
【问题描述】:

我正在 rmarkdown 上编写一个闪亮的应用程序。该应用程序假设在同一个图表上绘制两个时间序列,但第二个图是以复选框为条件的。

问题是,当复选框未选中时,整个图表都会消失,而不仅仅是与复选框相关的系列。

我目前正在使用来自 xtsExtra pkg 的 plot.xts,但我愿意尝试其他 pkg。唯一的限制是必须自定义颜色 (col) 和线宽 (lwd)。

---
title: "Untitled"
author: "gustavo"
date: "Saturday, November 29, 2014"
output: html_document
runtime: shiny
---


```{r, echo = FALSE}
require(xts)
require(xtsExtra)

x = rnorm(100)
y = rnorm(100)
idx = seq(as.Date("2000-01-01"), length = 100, by = "months")

Xxts = xts(cbind(x,y), order.by = idx)

checkboxInput("teste", "Teste", value = FALSE)

renderPlot({
  plot.xts(Xxts[,1],panel = 1)
  
  if(input$teste == TRUE){
  addSeries(Xxts[,2], on = 1, type="l")
  }
})

```

【问题讨论】:

    标签: r plot shiny xts


    【解决方案1】:

    将您的 renderPlot 更改为

    renderPlot({ 
      if(input$teste == TRUE){
        plot.xts(Xxts[,1],panel = 1)
        addSeries(Xxts[,2], on = 1, type="l")
      }else{
        plot.xts(Xxts[,1],panel = 1)
      }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      相关资源
      最近更新 更多