简体   繁体   English

从 Flexdashboard 下载数据

[英]Download data from Flexdashboard

I am working with RMarkdown file.我正在使用 RMarkdown 文件。 My file has elements of Shiny but works with flexdashboard.我的文件包含 Shiny 的元素,但适用于 flexdashboard。 Below you can see the code.您可以在下面看到代码。

---
title: "Test"
author: " "
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed
runtime: shiny
editor_options: 
  markdown: 
    wrap: 72
---



# Module 1

```{r global, include=FALSE}
library(biclust)
data(BicatYeast)
set.seed(1)
res <- biclust(BicatYeast, method=BCPlaid(), verbose=FALSE)

```



## Inputs {.sidebar}

```{r}
 selectInput("clusterNum", label = h3("Cluster number"), 
    choices = list("1" = 1, "2" = 2), 
    selected = 1)
```



## Row {.tabset}


### Parallel Coordinates

```{r}
num <- reactive(as.integer(input$clusterNum))

renderPlot(
  parallelCoordinates(BicatYeast, res, number=num()))

```

### Data for Selected Cluster

```{r}

renderTable(
  BicatYeast[which(res@RowxNumber[, num()]), which(res@NumberxCol[num(), ])]
)

```

With the dropdown menu, I can choose a dataset and chooses the data set I can see in the second tab titled as,Data for Selected Clusteer'.通过下拉菜单,我可以选择一个数据集,然后选择我可以在标题为“选定集群的数据”的第二个选项卡中看到的数据集。

在此处输入图像描述

Now I want to download the selected table by pressing the download button but I don't know how to do that.现在我想通过按下下载按钮来下载选定的表格,但我不知道该怎么做。 So can anybody help me how to solve this problem and download data into Excel format (*.xlsx).那么任何人都可以帮助我如何解决这个问题并将数据下载为 Excel 格式(*.xlsx)。

You need 2 components:您需要 2 个组件:

  1. The ability to write a data.frame to an Excel file (or alternativly, just to a CSV file or similar).能够将 data.frame 写入 Excel 文件(或者,仅写入 CSV 文件或类似文件)。
  2. Make a file downloadable in Shiny.在 Shiny 中制作一个可下载的文件。

For the former, take a look at the package openxlsx .对于前者,请查看 package openxlsx Avoid the older R package that relies on Java.避免依赖于 Java 的旧 R package。

For the latter, see this link https://shiny.rstudio.com/reference/shiny/1.0.4/downloadButton.html (you need to use a downloadLink or downloadButton, and the downloadHandler to generate the output).对于后者,请参阅此链接https://shiny.rstudio.com/reference/shiny/1.0.4/downloadButton.html (您需要使用 downloadLink 或 downloadButton,以及 downloadHandler 来生成输出)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM