2015-10-02 21 views
0

当使用ggvis和shiny + markdown时,每次更新我的图形时,都会打开一个新的浏览器窗口。markdown + shiny + 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)) 
}) 
``` 

我发现没有更新的例子,其中有光泽的变量被显式访问在本MWE ...

回答

0

通读ggvis的Properties and scales vignette,我现在认识到使用Shiny包装纸更容易: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)) 
``` 

我可以直接使用有光泽,但显然,我会告诉闪亮使用bind_shiny ggvis,并告诉闪亮有关使用ggvisOutput ggvis。

相关问题