How to fix download button sidebar issue in flexdashboard

落爺英雄遲暮 提交于 2020-03-17 08:47:48

问题


I have added a download button to my flexdashboard in the sidebar panel, but it appears in the main panel when I knit the .RMD. Can you please guide me as to how I can fix it?

Here's a minimal example of what I'm trying to accomplish

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

A screenshot of the dashboard is as follows

Thanks!


回答1:


Never mind, I fixed it and it was rather silly of me to have not tried it before posting the question, but if someone ever faces a similar problem, the solution is here.

The download handler function must simply be placed in the sidebar panel as well and that does it.

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


来源:https://stackoverflow.com/questions/37517677/how-to-fix-download-button-sidebar-issue-in-flexdashboard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!