Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DownloadButton width in R Flexdashboard

I'm having problems to change my DownloadButton width, since he's different from actionButton (which have the width parameter).

Any easy ideas to solve it? Here's my code (Just a simple download button):

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>
like image 302
Artur Guerra Avatar asked Oct 31 '25 07:10

Artur Guerra


1 Answers

Actually, after playing around with this I recommend to use uiOutput with renderUI.

Without using uiOutput the downloadButton function gets ignored (only the downloadHandler gets evaluated), that's why the width parameter was not set, and also you can't modify the label of the button.

There are all solved with using 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)
  }
)
```

I set the width using inlineCSS with the style argument, but you can (and should) use an external style sheet if you have multiple CSS rules.

Using an external stylesheet (CSS file)

An external CSS file can be used in Flexdashboard by adding css: path/filename.css to the YAML header.

---
title: "Full width downloadButton"
output: 
  flexdashboard::flex_dashboard:
    css: styles.css
runtime: shiny
---

In this case the app tries to read a file called styles.css in the same folder as the Rmd.

Create the css file in the same folder and add the rule:

#downBtn {
  width: 100%;
}

You can now remove style = "width:100%;" from the downloadButton and still get full width button.

Output:

output

like image 111
GyD Avatar answered Nov 02 '25 23:11

GyD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!