簡體   English   中英

在RMarkdown中使用閃亮的無功輸入來顯示表達式的輸出

[英]Displaying Output of Expression Using Shiny Reactive Input in RMarkdown

我的rmd文件在下面。 它應該很容易重現,因為它僅使用Sys.Date()和滑塊輸入。

---
output: html_document 
runtime: shiny
---

```{r, echo=FALSE, error=FALSE, message=FALSE}
sliderInput("daysback", "Days back from today: ", min=1, max=45, value=30, step=1)

renderText({input$daysback})

display_date = reactive({Sys.Date() - input$daysback})
observe(print(display_date()))
```

renderText({input $ daysback})正確顯示輸入值,並在用戶移動滑塊時對其進行更新。

但是observe(print(display_date))沒有顯示任何內容。 我從下面的示例中采用了observe(print())方法,從SO答案中使用了來自反應式輸入的值直接輸入到自定義函數中

num_square = reactive({input$num^2}) 
observe(print(num_square()))

另外,盡管當我單擊RStudio中的“運行文檔”時,查看器窗格中沒有顯示日期,但是當我在查看器窗格中移動滑塊時,RStudio控制台(RMarkdown-tab)正在顯示日期。 輸出示例(每次移動滑塊時都會添加一行):創建的輸出:

C:/Users/vuser/AppData/Local/Temp/RtmpSiQ52I/file125c17cd231.html [1]“ 2015-04-28” [1]“ 2015-05-08” [1]“ 2015-04-27” [1 ]“ 2015-05-03”

所以我不知道為什么它不會顯示在啟動的文檔中。

在這里操作。

renderPrint(displayDate())而不是observe(print(display_date()))對我renderPrint(displayDate()) 實際上,我實際上主要需要能夠顯示str(displayDate())來幫助我調試代碼中的其他內容。

無論如何,下面的代碼塊使用sliderInput和日期來創建解決方法日期滑塊,因為沒有閃亮的dateSlider輸入功能。 這就是我試圖解決的問題。

---
runtime: shiny
output: html_document
---

```{r}
sliderInput("sliderDays", "Days forward from 1/1/2015: ", min=1, max=45, value=1, step=1)

display_date = reactive({as.Date("2015-01-01") + input$sliderDays})
renderPrint(display_date())
```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM