0

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
---
library(flexdashboard)
library(readxl)
library(tidyverse)
library(shiny)
library(rhandsontable)
library(dplyr)
library(forecast)
library(fpp)
library("TTR")
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}

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

output$table1 <- renderRHandsontable({
  eventReactive(input$a,{
    rhandsontable(HW)
  })
})
rHandsontableOutput("table1")
Regolith
  • 2,944
  • 9
  • 33
  • 50
Dev P
  • 449
  • 3
  • 12

1 Answers1

0

You should not use eventReactive but observeEvent instead (check here). Also, this condition should be outside of the output part: "if I observe this event, then I will display this table" (and not "I will display this table and then fill it according to which button is ticked").

Here's the solution to your problem (you should customize it so that just selecting HoltWinters displays the table but at least you have a working basis here):

---
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}
observeEvent(input$a,{
  output$table1 <- renderRHandsontable({
     rhandsontable(HW)
    })
})
rHandsontableOutput("table1")
```

Edit: you can add a condition within the observeEvent so that the table is displayed only if HoltWinters is ticked:

observeEvent(input$a,{
  if (input$r == "HoltWinters") {
    output$table1 <- renderRHandsontable({
      rhandsontable(HW)
    })
  }
  else {
    output$table1 <- renderRHandsontable({
    })
  }
})
rHandsontableOutput("table1")
bretauv
  • 7,756
  • 2
  • 20
  • 57