Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ColinFay/handydandy

Easy CSS Styling for Shiny
https://github.com/ColinFay/handydandy

Last synced: 9 days ago
JSON representation

Easy CSS Styling for Shiny

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

# handydandy

The goal of {handydandy} is to provide an easy to use API for bringing style to a shiny app with CSS.

## Installation

You can install the dev version of {handydandy} with:

``` r
remotes::install_github("ColinFay/handydandy")
```

## Example

### Add, update, remove css elements

```{r example}
library(handydandy)

# Create a new dandy
css <- Dandy$new()

# It's easy to add a new style, you need to pass
# + a selector
# + a list of property = value

css$add_style("body", list("font-family" = "Helvetica",
"color" = "#24292e"))
css$add_style("h2", list("font-size" = "3 em",
"color" = "#911414",
"text-align" = "center"))
css

# Easy to update
css$update_style("body","color","#911414")
css

# Or to remove one
css$remove_style("body")
css

# You can also simply remove one part of your tag
css$remove_style("h2", "color")
css
```

### In a shiny app

The idea of course is to use it in shiny app:

```{r eval = FALSE}
css <- Dandy$new()

css$add_style("body", list("font-family" = "Helvetica",
"color" = "#24292e"))
css$add_style("h2", list("color" = "#911414",
"text-align" = "center"))
css$add_style("h3", list("color" = "#2E2E8F",
"text-align" = "center"))

ui <- fluidPage(
# Give swag to your app
css$swag(),
textInput("lol","lol", "lol"),
textOutput("lolilol"),
h2("lol"),
h3("pouet")
)

server <- function(input, output, session) {
output$lolilol <- renderText({
input$lol
})
}

shinyApp(ui, server)
```

![](readme-fig/handydandy.png)