2016-11-25 50 views
3

我是flex-dashboard的newby ... 如何在兩個不同的選項卡中分離輸入信息和輸出結果?舉個簡單的例子,我試圖渲染僅在第二個選項卡「輸出」Flex儀表板:不同標籤中的輸入和輸出

--- 
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%") 
) 
} 
``` 
+0

這是flex_dashboard,而不是shinydashboard – HubertL

+0

編輯問題 – Juanchi

回答

3

你忘記了用戶界面和服務器功能所需的一切,並把在夾頭對象直接像這樣barplot:

--- 
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") 
    }) 

``` 
+0

太棒了!簡單! – Juanchi

+0

你能幫我用這個http://stackoverflow.com/questions/40852523/r-flexdashboard-site-not-found-after-deloying – Juanchi