2017-05-12 34 views
0

我有两个动画ioslides,在单独的演示文稿中工作正常,但是在同一个演示文稿中导致错误'x' and 'y' lengths differ。这是我的MWE。'x'和'y'长度在一起不同,但在ioslides中没有分开

--- 
title: "Untitled" 
runtime: shiny 
output: ioslides_presentation 
--- 

##Outliers 

```{r, echo = FALSE, warning=FALSE} 
sliderInput("multiplier", label = "Distance:", max = 1.35, min = 1, value = 
1, ticks=FALSE, animate= 
      animationOptions(interval = 100, playButton = "run")) 

x  <- seq(5,15,length=50) 
Day1 <- rnorm(50,mean=10,sd=0.5) 

renderPlot({ 
Day1[22] <- max(Day1)*input$multiplier 
plot(x,Day1, ylim=c(8.5,15.5)) 
text(x=14, y=14.5, labels=paste0("Mean: ", round(mean(Day1),2))) 
text(x=14, y=14, labels=paste0("Median: ", round(median(Day1),2))) 
}) 
``` 

##bootstrap 
```{r, warning=FALSE} 
library(plyr) 
sliderInput("animation", "Number of samples:", 1,1000,1, step = 1, animate= 
      animationOptions(interval=30, loop=FALSE)) 

x=c() 
for (i in 1:1000) { 
x[i] <- round(rnorm(n=200, mean=10, sd=1),1) 
} 
dfx <- data.frame(x) 

renderPlot({ 
mp <- 
barplot(count(dfx[1:input$animation,])$freq,count(dfx[1:input$animation,])$x) 
    axis(1,at=mp,labels=count(dfx[1:input$animation,])$x) 
    legend("topright", legend=paste0("mean: 
",round(mean(dfx[1:input$animation,]),3)), bty="n") 
}) 

renderUI({ 
plotOutput("unsized", height = 500, width = 400) 
}) 
``` 

据推测这是一些小事,但是当我在看代码分开我找不到任何

回答

1

我认为这是与其中x /第一天放置。我通常把它这个样子,这似乎renderPlot函数内部工作对我来说:

```{r, echo = FALSE, warning=FALSE} 
inputPanel(
sliderInput("multiplier", label = "Distance:", max = 1.35, min = 1, value = 
1, ticks=FALSE, animate=animationOptions(interval = 100, playButton = "run")) 
) 

renderPlot({ 
x <- seq(5,15,length=50) 
Day1 <- rnorm(50,mean=10,sd=0.5) 
Day1[22] <- max(Day1)*(input$multiplier) 
plot(x,Day1, ylim=c(8.5,15.5)) 
text(x=14, y=14.5, labels=paste0("Mean: ", round(mean(Day1),2))) 
text(x=14, y=14, labels=paste0("Median: ", round(median(Day1),2))) 
}) 
``` 
+0

或者你可以定义'x'和'Day1'作为第一 – timfaber

+0

你能给如何定义'为例反应值x'和'Day1'作为反应价值第一? –

相关问题