我有一个数据框,请帮助我执行此操作。当我检查“ HoltWinters”并按“ Execute”按钮时,应出现数据框“ HW”。我已经尝试了一半。但是请在这里需要任何人的帮助.......................................
---
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)
模型执行
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")
答案 0 :(得分:0)
您不应使用eventReactive
,而应使用observeEvent
(选中here)。另外,此条件应位于output
部分之外:“如果观察到此事件,则将显示此表”(而不是“将显示此表,然后根据被选中的按钮填充它”) )。
这是您问题的解决方案(您应该对其进行自定义,以便仅选择HoltWinters即可显示表格,但至少在这里有工作依据):
---
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")
```
编辑:您可以在observeEvent
内添加条件,以便仅在选中HoltWinters时显示表格:
observeEvent(input$a,{
if (input$r == "HoltWinters") {
output$table1 <- renderRHandsontable({
rhandsontable(HW)
})
}
else {
output$table1 <- renderRHandsontable({
})
}
})
rHandsontableOutput("table1")