r - R Flexdashboard 中的下载按钮宽度

标签 r shiny 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>

最佳答案

实际上,在尝试了这个之后,我建议将 uiOutputrenderUI 一起使用。

如果不使用 uiOutputdownloadButton 函数将被忽略(仅评估 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%;" 并仍然获得全宽按钮。

输出:

output

关于r - R Flexdashboard 中的下载按钮宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345498/

相关文章:

r - 在 R 中与 dplyr 连接时嵌套重复变量

r - 设置一个绘图缩放以匹配 Shiny 中另一个绘图缩放的缩放

R Shiny 仪表板,更改所有超链接的颜色

r - 在flexdashboard中的菜单内创建菜单 - R

r - 将 flexdashboard 中的 R markdown 标题链接到应用程序中的页面

使用 flexdashboard 模板再现光泽

r - 使用 KnitR 的 R 图中的 LaTeX 图形标签?

r - 如何从 R 中的数据框中删除带有 inf 的行

string - 替换字符串列表中的特殊字符和空格

r - 如何在 session 关闭时删除 Shiny 应用程序创建的文件