Plotting after Checking the radio Button and Pressing action Button

Hi all,

I have a dataframe, please help me in executing this. The moment I check "HoltWinters" and press "Execute" button, dataframe "HW" should appear. I have tried half way. But need anyone help here please

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(tidyverse)
library(shiny)
library(rhandsontable)
library(dplyr)
library(forecast)
library(fpp)
library("TTR")
```

```{r}
x <- c(1:123)
x <- ts(x, start = c(2017, 23), end = c(2019, 39), frequency = 53)
x.hw <- HoltWinters(x)
HW <- forecast(x.hw, h = 6)
HW <- as.data.frame(HW)
```

Model Execution
=================

Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
radioButtons("r",h5("Models"),choices = list("Regression", "Arima","HoltWinters","Model4","Model5"),selected = "No", inline = F)
actionButton("a","Execute",icon = NULL)
```

   
Row {.tabset .tabset-fade}
-------------------------------------
   
### HoltWinters

```{r}
output$table1 <- renderRHandsontable({
  eventReactive(input$a,{
    rhandsontable(HW)
  })
})
rHandsontableOutput("table1")
```

Hi all,

I tried with the below code. It is almost working. But small change is needed. I do get output after I select "HoltWinters" and press "Execute" Button. But when I select other Radiobuttons and come back to "HoltWinters", the output still appears without me pressing "Execute" Button. Please guide

```{r}
table1 <- eventReactive(input$a,{
    req(input$r)
    rhandsontable(HW,width = 500)
  })

output$table1 <- renderRHandsontable({ 
      req(input$a)
      req(input$r)
      if (input$r == "HoltWinters"  && input$a) {
        table1()
      }
    })
rHandsontableOutput("table1")

Your example doesn't make use of the radioButtons control at all, but this would be the pattern to use the actionButton

```{r}
observeEvent(input$a,{
  output$table1 <- renderRHandsontable({
    rhandsontable(HW)
  })
})
rHandsontableOutput("table1")
```
1 Like

Thanks. I got this actually. But is there a way to incorporate the function of Radiobuttons as well. The example you shared gives the output once the button is pressed irrespective of whatever the Radiobuttons are there?

There can be many ways, it depends on how you want to design the reactivity, for example, this would show the table only if "HoltWinters" is selected.

```{r}
observeEvent(input$a,{
  if (input$r == "HoltWinters") {
    output$table1 <- renderRHandsontable({
      rhandsontable(HW, width = 500)
    })
  }
})
rHandsontableOutput("table1")
```
1 Like

Perfect and thanks a lot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.