R Flexdashboard 中的下载按钮宽度
DownloadButton width in R Flexdashboard
我在更改 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)
}
)
```
我使用 inlineCSS 和 style
参数来设置 width
,但是您可以(并且应该)使用外部样式sheet 如果您有多个 CSS 规则。
使用外部样式sheet(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%;"
,但仍会得到全宽按钮。
输出:
我在更改 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)
}
)
```
我使用 inlineCSS 和 style
参数来设置 width
,但是您可以(并且应该)使用外部样式sheet 如果您有多个 CSS 规则。
使用外部样式sheet(CSS 文件)
通过将 css: path/filename.css
添加到 YAML header.
---
title: "Full width downloadButton"
output:
flexdashboard::flex_dashboard:
css: styles.css
runtime: shiny
---
在这种情况下,应用程序会尝试读取与 Rmd
.
styles.css
的文件
在同一文件夹中创建 css 文件并添加规则:
#downBtn {
width: 100%;
}
您现在可以从 downloadButton
中删除 style = "width:100%;"
,但仍会得到全宽按钮。