在Rmarkdown闪亮的演示文稿中动态创建幻灯片

时间:2017-10-19 10:05:14

标签: shiny r-markdown

我希望在我的Rmarkdown演示文稿中动态生成幻灯片,并带有闪亮的

以下代码适用。
但是,只要我取消注释for循环,它就不会。

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

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r, echo = FALSE, results = "asis"}
number_of_bins_selected <- c(20,30)

i <- 1 # If for loop commented
#for (i in 1:length(number_of_bins_selected)) {

  cat("## New slide  \n")

  input1_id <- paste(i, "nbreaks", sep = "_")
  input2_id <- paste(i, "bw_adjust", sep = "_")

  inputPanel(
    selectInput(input1_id, label = "Number of bins:",
                choices = c(10, 20, 35, 50), selected = number_of_bins_selected[i]),

    sliderInput(input2_id, label = "Bandwidth adjustment:",
                min = 0.2, max = 2, value = 1, step = 0.2)
  )

  renderPlot({
    hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input[[input1_id]]),
         xlab = "Duration (minutes)", main = "Geyser eruption duration")

    dens <- density(faithful$eruptions, adjust = input[[input2_id]])
    lines(dens, col = "blue")
  }) 
  cat("  \n\n") # End the slide
#}

```

是否可以在for循环中创建幻灯片?

0 个答案:

没有答案