首页 文章

用Shiny Rmarkdown中的动作按钮绘图

提问于
浏览
3

我很好奇以下为什么不起作用 . 当试图使用对动作按钮的反应进行绘图时,它无法在Shiny中显示情节 .

知道我做错了什么吗?我尝试了很多迭代和方法 . 任何想法,如果Shiny可以在被动环境中调用时产生情节?

---
title: "Will not plot"

output: html_document

runtime: shiny

---


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

 inputPanel(
  actionButton("Plot", "Save and Open TRI"),
  numericInput("Size", label = "Size", value = 1000, 1000, 5000, 1000)
              )
# Works:
renderPlot({
plot(runif(1000)
     )})

# Doesn't work:
eventReactive(input$Plot,
{
  renderPlot({
plot(runif(1000)
 )})
}
)

observeEvent(input$Plot,
{
  renderPlot({
    plot(runif(1000)
     )})
}
)

1 回答

  • 4

    这应该做到这一点

    ---
    title: "Will not plot"
    output: html_document
    runtime: shiny
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)  
    
    
     inputPanel(
      actionButton("Plot", "Save and Open TRI"),
      numericInput("Size", label = "Size", value = 1000, 1000, 5000, 1000)
                  )
    
    p <- eventReactive(input$Plot, {plot(runif(1000))})
    
    renderPlot({
      p()
      })
    
    
    
    参考:[Shiny Action Buttons](http://shiny.rstudio.com/articles/action-buttons.html)  - 尤其见 **pattern 2 - eventReactive**  .

相关问题