markdown+shiny+ggvis:图形在新浏览器中更新 window

markdown+shiny+ggvis: graphics updated in new browser window

将 ggvis 与 shiny+markdown 一起使用时,每次我的图形更新时,都会打开一个新的浏览器 window。

考虑以下 MWE:

---
title: "a"
author: "b"
date: "2015"
output: html_document
runtime: shiny
---

Works fine when using base graphics:

```{r,echo=FALSE}
X <- data.frame(t=1:50,x=arima.sim(list(1,0,0),50))
inputPanel(
    sliderInput('p','p',0,2,0,1,TRUE),
    sliderInput('n','n',0,1,0.5,0.1,TRUE)
)
renderPlot({
    plot(X)
    lines(predict(loess(x~t,X,span=input$n,degree=input$p),X$t),col='red')
})
```

When using ggvis, the graphic is updated in a new window!

```{r,echo=FALSE}
library(ggvis)
inputPanel(
    sliderInput('p','p',0,2,0,1,TRUE),
    sliderInput('n','n',0,1,0.5,0.1,TRUE)
)
renderPlot({
    X %>% ggvis(x=~t,y=~x) %>% layer_points() %>%
        layer_model_predictions(stroke:='red',model='loess',formula=x~t,
            model_args=list(span=input$n,degree=input$p))
})
```

我没有发现像在这个 MWE 中那样显式访问 Shiny 变量的更新示例...

通读了 ggvis 的 Properties and scales vignette,我现在意识到使用他们的 Shiny wrapper 更容易:input_slider 而不是 sliderInput

因此,之前的代码将变为:

```{r,echo=FALSE}
X %>% ggvis(x=~t,y=~x) %>% layer_points() %>%
        layer_model_predictions(stroke='red',model='loess',formula=x~t,
            model_args=list(
                span=input_slider(0,2,1,1,TRUE),
                degree=input_slider(0,1,0.01))
```

我本可以直接使用 Shiny,但显然,我必须使用 bind_shiny 告诉 ggvis 有关 shiny 的信息,并使用 ggvisOutput.

告诉 shiny 有关 ggvis 的信息