2017-02-20 9 views
0

Rマークダウン文書の光沢のある出力に反応テスト(te)を追加できません。 Rスタジオの例に基づく最小の例は、以下のペーストです。Rマークダウン原稿に反応性のあるテキストを含める

事前に感謝します。 ジャン=ピエール・

--- 
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") 
}) 
``` 

答えて

1

私はあなたが、renderPlotteを定義するためにte <<- reactive(startTime - endTime)を使用し、それは反応式ですのでrenderText({te()})の代わりrenderText({te})を使用し、そして最終的にそれの定義の後に最後にrenderText({te()})を置くべきだと思います。

+0

これは素晴らしいことです!私はこれがどのように機能するかを理解しようと多くの時間を無駄にしてきました。あなたは私の一日を救った! – gattuso

関連する問題