R - markdown+shiny+ggvis:在新的浏览器窗口中更新图形



当使用带有shiny+markdown的ggvis时,每次我的图形更新时,都会打开一个新的浏览器窗口。

考虑以下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))
})
```

我发现没有更新的例子,其中Shiny变量显式访问在这个MWE…

通读ggvis的属性和尺度小插图,我现在意识到使用它们的闪亮包装器更容易: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