gpt4 book ai didi

r - 如何修复 flexdashboard 中的下载按钮侧边栏问题

转载 作者:行者123 更新时间:2023-12-04 03:49:52 25 4
gpt4 key购买 nike

我在侧边栏面板的 flexdashboard 中添加了一个下载按钮,但是当我编织 .RMD 时它出现在主面板中。你能指导我如何解决它吗?

这是我试图完成的一个最小的例子

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

谢谢!

最佳答案

没关系,我修复了它,在发布问题之前没有尝试过我很愚蠢,但是如果有人遇到类似的问题,解决方案就在这里。

下载处理程序函数也必须简单地放在侧边栏面板中,就可以了。

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

关于r - 如何修复 flexdashboard 中的下载按钮侧边栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37517677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com