I am curious as to why the following does not work. When trying to plot using a reaction to an action button, it fails to show the plot in Shiny.
Any idea what I am doing wrong? I have tried many iterations and ways of doing this. Any ideas if Shiny can generate a plot when called in a reactive environment?
---
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)
)})
}
)
```
This should do it
---
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()
})
```
Reference: Shiny Action Buttons - see pattern 2 - eventReactive in particular.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With