【问题标题】:Include reactive text in a R markdown shiny documents在 R markdown 闪亮文档中包含反应文本
【发布时间】:2017-07-09 19:41:08
【问题描述】:

我有点迷茫,无法在 R markdown 文档的闪亮输出中添加反应测试 (te)。下面粘贴了一个基于 R studio 示例的最小示例。

提前非常感谢! 让-皮埃尔

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

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

```{r eruptions, echo=FALSE}
inputPanel(
  selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20),

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

renderText({te})

renderPlot({
startTime <- Sys.time()
  # additional code goes here
endTime <- Sys.time() +1
te <- reactive(startTime - endTime)
hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)", main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

【问题讨论】:

    标签: r shiny markdown r-markdown


    【解决方案1】:

    我认为你应该使用te &lt;&lt;- reactive(startTime - endTime)renderPlot之外定义te,使用renderText({te()})而不是renderText({te}),因为它是一个反应式表达式,最后在定义后将renderText({te()})放在末尾.

    【讨论】:

    • 太棒了!我浪费了很多时间试图弄清楚这是如何工作的。你拯救了我的一天!
    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多