2016-05-30 28 views
6

我已經在側欄面板的我的flexdashboard中添加了一個下載按鈕,但它在我編織.RMD時出現在主面板中。你能指導我如何解決它嗎?如何解決flexdashboard中的下載按鈕邊欄問題

這裏是什麼,我試圖完成

--- 
title: "Download Button in Wrong Panel" 
output: 
    flexdashboard::flex_dashboard: 
    vertical_layout: scroll 
runtime: shiny 
--- 

```{r setup, include=FALSE} 

## Setting up required libraries 
library(flexdashboard) 
library(dplyr) 
library(shiny) 
library(knitr) 

dataset <- read.csv(somefile) 
``` 

Inputs {.sidebar} 
----------------------------------------------------------------------- 

### Input Filters 

```{r input} 

## Metric 1 
selectInput('metric', 
      'Choose Metric', 
      names(dataset %>% select(-default_column)), 
      selected = "default_metric") 

## Download Button 
downloadButton('downloadData','Download Result Set') 
``` 

Outputs 
----------------------------------------------------------------------- 

### List of Customers 

```{r output} 

subset_dataset <- reactive({ 
    dataset[,c("default_column",input$metric)] 
}) 

renderTable({ 
    subset_dataset() 
}, 
include.rownames = FALSE) 

downloadHandler(filename = function() { 
    paste('resultset-', Sys.Date(), '.csv', sep='') 
    }, 
    content = function(file) { 
    write.csv(subset_dataset(), file, row.names = FALSE) 
    } 
) 
``` 

儀表板的屏幕截圖如下

enter image description here

由於小例子!

回答

5

沒關係,我解決了它,在發佈問題之前沒有嘗試過它,這真的很愚蠢,但如果有人遇到類似問題,解決方案就在這裏。

下載處理程序功能必須簡單地放置在側邊欄面板中,並且這樣做。

Inputs {.sidebar} 
----------------------------------------------------------------------- 

### Input Filters 

```{r input} 

## Metric 1 
selectInput('metric', 
      'Choose Metric', 
      names(dataset %>% select(-default_column)), 
      selected = "default_metric") 

## Download Button 
downloadButton('downloadData','Download Result Set') 

downloadHandler(filename = function() { 
    paste('resultset-', Sys.Date(), '.csv', sep='') 
    }, 
    content = function(file) { 
    write.csv(subset_dataset(), file, row.names = FALSE) 
    } 
) 
相關問題