我很好奇以下原因为何不起作用。尝试使用对动作按钮的反应进行绘图时,它无法在Shiny中显示绘图。
知道我在做什么错吗?我尝试了许多迭代和方法。有什么想法可以让Shiny在反应性环境中调用时可以生成图吗?
---
title: "Will not plot"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo = FALSE}
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)
)})
}
)
```
Run Code Online (Sandbox Code Playgroud)
这应该做
---
title: "Will not plot"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo = FALSE}
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()
})
```
Run Code Online (Sandbox Code Playgroud)
参考:发光操作按钮 -参见模式2-特别是eventReactive。
| 归档时间: |
|
| 查看次数: |
2714 次 |
| 最近记录: |