DownloadButton width in R Flexdashboard - r

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>

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:

Related

Add rho as icon in valueBox

Can I add a rho (Greek letter small) as an icon to a value box in RShiny?
For example, with the following code snippet, I have created a value box that has the € symbol as an icon:
valueBox(winterMean, subtitle = "Mean Winter", color = "black", icon = icon("euro-sign"))
This gives the following value box:
How can I replace the € symbol by a small rho?
We can add custom Greek letters using Unicode Character "ρ" (U+03C1) through custom css, see example:
Using flexdashboard:
Our example rmd file:
---
title: "My Rho"
output:
flexdashboard::flex_dashboard:
css: styles.css
---
```{r}
library(flexdashboard)
valueBox(42, caption = "My Rho", icon = "fa-rho")
```
And additional styles.css file:
.fa-rho:before {
font-weight: 700;
content: '\03c1';
}
Output:
Note: For my test I kept css file in the same folder as rmd file, but it could be in any subfolder, then we need to define the full path in rmd, e.g.: resources/css/styles.css.
Using shinydashboard
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
includeCSS("styles.css"),
valueBox(42, "My Rho", icon = icon("rho")),
)
)
server <- function(input, output) { }
shinyApp(ui, server)
Output:

change CSS of single element from shinyWidgets in flexdashboard

Related to questions here and here, I would like to change the CSS of a pickerInput menu from ShinyWidgets. I am using flexdashboard and I would like the styling to match exactly that from the selectInput menu. I realize I can do this by setting the overall theme in the YAML to bootstrap, but I'd prefer not to use a global solution.
---
title: "Testing picker styles"
output:
flexdashboard::flex_dashboard
runtime: shiny
---
```{r setup, include=F}
library(shiny)
library(flexdashboard)
library(shinyWidgets)
```
Column
-----------------------------------------------------------------------
```{r}
selectInput(inputId = "id1", label = "Select input", choices = attr(UScitiesD, "Labels"))
pickerInput(inputId = "id2", label = "Picker input", choices = attr(UScitiesD, "Labels"))
```
pickerInput is styled like a Bootstrap button, and {flexdashboard} use Bootswatch's Cosmo theme (https://bootswatch.com/3/cosmo/) that's why it appears black.
You can change the class of the button with :
options = pickerOptions(style = "btn-link")
(in pickerInput arguments)
Or you can overwrite the base style like this :
options = list("style-base" = "form-control", style = "")

How do I add css style element to Rmd shiny renderImage?

I am struggling to add css style element to my shiny renderImage code.
I have tried various options with css source file via tag$link as well as with straight css code via tag$style.
I have tried both the tag$link as well as the tag$style options (in my sample code)
(1) outside of the renderImage code
(2) inside the renderImage code, outside of the list wrapper
(3) inside the renderImage code, inside of the list wrapper
I get one of two errors:
Error 1: Object of type 'closure' is not subsettable
Error 2: Object 'centerImage' not found
With my logo5.png image on my local machine, with no additional css - it works.
With my logo5.png image on my local machine, with additional css - it DOES NOT work.
Note that I left the '1', dir() and '2' in my code prior to renderImage to track execution.
Can someone please help?
(To run in Rstudio, change the rrr`` to the 3 back quotes in 4 places)
(My online image URL is http://www.richpat.com/wp-content/uploads/2019/04/logov5.png)
---
title: 'Shiny Dev with Logo'
output:
flexdashboard::flex_dashboard:
theme: united
orientation: columns
source_code: embed
runtime: shiny
---
rrr``{r setup, include=FALSE} #CORRECT THIS WHEN RUNNING
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(flexdashboard,quietly=TRUE, verbose=FALSE)
library(shiny,quietly=TRUE, verbose=FALSE)
library(plotly,quietly=TRUE, verbose=FALSE)
rrr`` #CORRECT THIS WHEN RUNNING
Corporate
=======================================================================
Column
-----------------------------------------------------------------------
### Logo
rrr``{r} #CORRECT THIS WHEN RUNNING
(1)
dir()
#tag$head(tags$link(rel = "stylesheet", type = "text/css", href = "BRstyle.css"))
#tag$head(tag$style("centerImage {text-align:center;}"))
(2)
renderImage({
rfilename=normalizePath("logov5.png")
list(src=rfilename, contentType = "image/png", alt = "logo5", class=centerImage)
}, deleteFile = FALSE)
rrr`` #CORRECT THIS WHEN RUNNING
Background
=======================================================================
Column
-----------------------------------------------------------------------
### Purpose
ad valorem libram
OK - so I found the answer. And simplicity is the route...
Instead of doing this in shiny renderImage, I learned a lot about how shiny and flexdashboard and markdown work together !!!
I used img html tag as part of the markdown section with direct display tags
<img src="http://www.richpat.com/wp-content/uploads/2019/04/logov5.png"
alt="Markdown Monster icon"
style="ftext-align:center; display: center;" />
And I removed the complete shiny renderImage r-code section
As a bonus - and just to show a bit more of what I learned, here is my revised yaml
title: 'Br F A'
output:
flexdashboard::flex_dashboard:
logo: logov5s.png
theme: readable
css: BRstyle.css
navbar:
- { title: "About", href: "http://www.richpat.com", align: left }
source_code: embed
orientation: columns
runtime: shiny

How to disable button based on a condition in a R Markdown document with shiny elements?

Suppose we have a group of 8 checkboxes (8 letters) and an action button which prints the label of all the selected checkboxes. What I want to do, enable and disable the state of the action button based on a condition. The condition is that if the number of selected checkboxes are between 2 and 5, then the button should be enabled, else disabled. For changing the state of the button I want to use the functions enable, disable or toggleState functions from the shinyjs package. And when the button is enabled, I will be able to trigger an event to print the numbers of selected items.
Here is what I tried until now:
---
title: "Disable Button"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shinyjs)
library(shiny)
```
```{r, echo=FALSE}
checkboxGroupInput("param_group", label = h3("Letters"),
choices = LETTERS[1:8])
actionButton('action', "Print")
result<-reactive({
length(input$param_group)
})
observe({
if(result()>1 & result()<=5)
enable("action")
else
disable("action")
})
txt<-eventReactive(input$action,{
cat("Number of letters selected: ",length(input$param_group))
})
renderPrint({
txt()
})
```
Took me awhile to find it, but you have to enable shinyjs to use R-markdown explicitly, it needs to setup its javascript differently in this case.
You do this by calling: useShinyjs(rmd=T) in the chunk where you are using it.
---
title: "Disable Button"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shinyjs)
library(shiny)
```
```{r, echo=FALSE}
useShinyjs(rmd=T)
checkboxGroupInput("param_group", label = h3("Letters"),
choices = LETTERS[1:8])
actionButton('action', "Print")
result<-reactive({
length(input$param_group)
})
observe({
useShinyjs()
if(result()>1 & result()<=5){
enable("action")
} else {
disable("action")
}
})
txt<-eventReactive(input$action,{
cat("Number of letters selected: ",length(input$param_group))
})
renderPrint({
txt()
})
Screen shot:

How to make shinyAce app container background transparent

I created a shiny presentation using rmarkdown in which one of the slides includes a shinyAce editor (code below). The entire app seems to be inside a container which has a white background. I want to make the background of this container transparent using css, but has thus far I've been unable to find the right object name to apply the change to.
I've tried a simple par(bg = NA) and tooled around in the default css files in the rmarkdown, shiny, and shinyAce packages...but cant find the appropriate place to make the change.
Finally, I've included code in mainPanel to change the color of the background. However, this just seems to be an overlay on the white container because when I set body {background-color: transparent} the background remains white.
As always, any help is appreciated
---
title : "White Backgrounds are Ugly"
subtitle : "Help me make it go away"
author : "Me"
date : "Now"
output:
ioslides_presentation:
widescreen : true
runtime: shiny
---
## Basic R Plot with shinyAce
```{r, echo=FALSE}
library(shinyAce)
shinyApp(
shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(
aceEditor("code", mode="r",
value="plot(1:5, 1:5,\nxlab = 'This is side 1',\nylab = 'This is side 2',\nmain = 'This is side 3',\nsub = 'Subtitle or Caption',\naxes = TRUE,\ntype = 'p',\nlas = 0)"),
actionButton("eval", "Evaluate")),
mainPanel(list(tags$head(tags$style("body {background-color: rgba(255,130,255,1); }"))), plotOutput("output"))))),
shinyServer(function(input, output, session) {
output$output <- renderPlot({
par(bg = NA)
input$eval
return(isolate(eval(parse(text=input$code))))
})
})
)
```

Resources