![](/img/trans.png)
[英]Create an input variable that is dependent on another input variable in flexdashboard shiny widget
[英]How to use shiny input variables in a global variable in flexdashboard
我有一個問題,我必須接受選擇輸入值並在函數中使用,但是我不能在多個Renders(繪圖,打印,表格)中調用該函數,因為這是一個昂貴的函數。 有了閃亮的輸入,我也想創建一個過濾數據和其他變量。 我得到的錯誤方法是:
沒有活動的響應上下文,不允許進行操作。
這只是一個簡單的例子。
---
title: "TITLE"
output:
flexdashboard::flex_dashboard:
orientation: row
vertical_layout: fill
theme: flatly
runtime: shiny
---
```{r global, include=FALSE}
require(flexdashboard)
require(ggplot2)
df <- data.frame(year = c("2013", "2014", "2015", "2013", "2014", "2015", "2013", "2014", "2015"),
cat = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
freqA = c(100, 100, 110, 80, 80, 90, 90, 90, 100),
freqB = c(50, 50, 55, 40, 40, 45, 45, 45, 50))
plus <- function(a,b){
return(a + b)
}
```
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
selectInput("a","select A:", c("freqA","freqB"))
selectInput("b","select B:", c("freqA","freqB"))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Itens mais frequentes
```{r}
sum <- plus(df[,input$a], df[input$b])
```
### Chart C
```{r}
```
Column {data-width=650,data-high=10}
-----------------------------------------------------------------------
### Relações
```{r}
```
錯誤消息就是這樣說的:您只能在反應式表達式中使用reactives
(例如輸入元素)。
這是因為每次輸入元素更改時,都必須重新渲染輸出,並且您只能在reactive context
執行此操作。
編輯:
reactive
變量: 內容將被緩存,因此即使您在不同的塊中使用它,它也只能運行一次:
```{r}
sum <- reactive( {
plus(df[,input$a], df[input$b])
})
```
renderPrint
使用稱為sum
的反應式表達式: 請注意,您可以像訪問函數一樣訪問reactives
(即: sum()
)
### Itens mais frequentes
```{r}
renderPrint( {
sum()
})
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.