我在更改 DownloadButton 宽度时遇到问题,因为他不同于 actionButton(具有宽度参数)。
有什么简单的办法可以解决吗? 这是我的代码(只是一个简单的下载按钮):
Normalidade
=======================================================================
Inputs {.sidebar}
-----------------------------------------------------------------------
<h5>
```{r}
tags$hr()
downloadButton("downloadNormal",label = "Download seu teste", class = "butt1")
downloadHandler(
filename = "Resultados_Normal.csv",
content = function(file) {
write.csv(data, file)
}
)
tags$hr()
tags$br()
actionButton("AjudaNormal", label = " Ajuda", icon("question-circle"),
width = "100%",
onclick="window.open('http://google.com', '_blank')")
```
</h5>
最佳答案
实际上,在尝试了这个之后,我建议将 uiOutput
与 renderUI
一起使用。
如果不使用 uiOutput
,downloadButton
函数将被忽略(仅评估 downloadHandler
),这就是为什么 width
没有设置参数,也不能修改按钮的标签。
使用 uiOutput
都可以解决。
---
title: "Full width downloadButton"
output:
flexdashboard::flex_dashboard:
css: styles.css
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
# Create placeholder for the downloadButton
uiOutput("downloadUI")
```
```{r}
# Create the actual downloadButton
output$downloadUI <- renderUI( {
downloadButton("downBtn", "Download Iris data", style = "width:100%;")
})
# Add download handling
output$downBtn <- downloadHandler(
filename = function() {
"iris.csv"
},
content = function(file) {
write.csv(iris, file, row.names = FALSE)
}
)
```
我使用带有 style
参数的 inlineCSS 设置了 width
,但是如果你有,你可以(并且应该)使用外部样式表多个 CSS 规则。
使用外部样式表(CSS 文件)
通过将 css: path/filename.css
添加到 YAML header ,可以在 Flexdashboard 中使用外部 CSS 文件。
---
title: "Full width downloadButton"
output:
flexdashboard::flex_dashboard:
css: styles.css
runtime: shiny
---
在这种情况下,应用程序会尝试读取与 Rmd
相同的文件夹中名为 styles.css
的文件。
在同一文件夹中创建 css 文件并添加规则:
#downBtn {
width: 100%;
}
您现在可以从 downloadButton
中删除 style = "width:100%;"
并仍然获得全宽按钮。
输出:
关于r - R Flexdashboard 中的下载按钮宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345498/