Flex仪表板:不同选项卡中的输入和输出

时间:2016-11-25 21:07:21

标签: r dashboard

我是flex-dashboards的新手...... 如何在两个不同的选项卡中分隔输入信息和输出结果?这是一个简单的例子,我试图只渲染第二个标签“输出”中的条形图

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
data(WorldPhones)
```

Inputs
=======================================================================

```{r, include=FALSE}
# Shiny module definition (would typically be defined in a separate R script)

# UI function
worldPhonesUI <- function(id) {
  ns <- NS(id)
  fillCol(height = 600, flex = c(2, 1),
    inputPanel(
      selectInput(ns("region"), "Region1:", choices = colnames(WorldPhones))
    )
  )
}

# Server function
worldPhones <- function(input, output, session) {
  output$phonePlot <- renderPlot({
    barplot(WorldPhones[,input$region]*1000, 
            ylab = "Number of Telephones", xlab = "Year")
  })
}
```

```{r, eval=TRUE}
# Include the module
worldPhonesUI("phones")
callModule(worldPhones, "phones")
```

Results
=======================================================================

```{r}
worldPhonesUI <- function(id) {
  ns <- NS(id)
  fillCol(height = 600, flex = c(NA, 1),
    plotOutput(ns("phonePlot"), height = "80%")
  )
}
```

1 个答案:

答案 0 :(得分:4)

你忘记了关于ui和服务器功能的所有内容,并将对象直接放在chuck中:

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
data(WorldPhones)
```

Inputs
=======================================================================

```{r}

selectInput("region", "Region1:", choices = colnames(WorldPhones))

```

Results
=======================================================================

```{r}
renderPlot({
    barplot(WorldPhones[,input$region]*1000, 
            ylab = "Number of Telephones", xlab = "Year")
  })

```