The rheroicons
packages brings to the Heroicons icon
library, developed by Adam
Wathan and Steve Schoger,
as R functions for use in your R-based web projects.
All icons are rendered as inline SVG icons. Therefore, no CSS or JavaScript dependencies are loaded into your Shiny application or other web document at runtime!
Install the stable version from CRAN.
install.packages("rheroicons")
The main branch of this repository and the latest release will always be even with the CRAN release. All development will take place on a new branch, and then merged with main when all tests have passed. New releases may be available prior to CRAN acceptance. If this is the case, you can download the GitHub release using the following command. Please note that release may change if revisions were requested.
::install_github("davidruvolo51/rheroicons@*release") remotes
There are over 200 icons in the collection. Each icon has three
styles: outline, solid, and mini. The rheroicons
package
includes an icon gallery that can be used to find icons and copy the R
code.
::launch_gallery() rheroicons
In the gallery, click the name of an icon to copy the R code, and then paste the R code directly into your Shiny application.
Alternatively, you can use the find_icon
function to
search for icons.
# returns all icon names
::find_icons()
rheroicons
# find icons with `chevron` in the name
::find_icons(query = "chevron")
rheroicons
# find icons with `chevron` OR `arrow` in the name
::find_icons(query = "chevron|arrow")
rheroicons
# find icons with `down`, `up`, `left`, OR `right` in the name
::find_icons(query = "down|up|left|right")
rheroicons
# find icons that end with `down`.
::find_icons(query = "(down)$") rheroicons
You can also use the Heroicons site to find icons.
When you have found the icon that you would like to use, you can
render them into your app or web document using the
rheroicon
function.
# rheroicons version of the magnifying glass circle icon
::rheroicon(name = "magnifying-glass-circle") rheroicons
The rheroicon
function takes the following
arguments.
Argument | Description | Options | Default |
---|---|---|---|
name |
icon name | (use find_icon or launch_gallery ) |
— |
type |
icon style | outline , solid , mini |
outline |
class |
add your own CSS classes | — | NULL |
Example use:
library(shiny)
$button(
tagsid = "copy",
class = "button button-copy",
$span("Add to clipboard"),
tags::rheroicon(
rheroiconsname = "clipboard-document",
type="solid"
) )
Use the argument class
to add custom CSS classes to an
icon.
library(shiny)
$button(
tagsid = "copy",
class = "button button-copy",
$span("Add to clipboard"),
tags::rheroicon(
rheroiconsname = "clipboard-document",
type = "solid",
class = "button-icon"
) )
However, you may find it easier to use the predefined classes generated by this package. All icons have three types of CSS classes.
rheroicons
rheroicons-outline
, rheroicons-solid
,
or rheroicons-mini
rhericons-*
, where *
is the name of
the icon. (This is same as the icon name.)The following table displays the CSS classes by set for the
backspace
icon.
::rheroicon(name = "backspace") rheroicons
Icon Set | Function | CSS classes |
---|---|---|
outline | rheroicon(name ="backspace") |
rheroicons rheroicons-outline rheroicons-backspace |
solid | rheroicon(name ="backspace", type = "solid") |
rheroicons rheroicons-solid rheroicons-backspace |
mini | rheroicon(name ="backspace", type = "mini") |
rheroicons rheroicons-mini rheroicons-backspace |
You can select and style icons via CSS using these classes. Create a
new tags$style
element and define your styles (or use an
external CSS file).
library(shiny)
# ui
<- tagList(
ui $head(
tags$style(
tags
# select all instances of rheroicons
".rheroicons {
width: 50px;
height: 50px;
}",
# select all outline icons (set color via the stroke property)
".rheroicons-outline {
stroke: green;
}",
# select solid icons (set color via the fill property)
".rheroicons-solid {
fill: red;
}",
# select specific icons
".rheroicons-home {
width: 75px;
height: 75px;
}",
# select specific icon of a particular style
".rheroicons-outline.rheroicons-home {
stroke: yellow;
}"
)
)# define UI here
... )
The following code demonstrates how to generate icons in Shiny, render solid and outlined icons, and style icons using CSS.
library(shiny)
<- tagList(
ui $head(
tags$style(
tags"body {
font-size: 16pt;
background-color: #f6f6f6;
font-family: Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}",
"main {
margin: 0 auto;
box-sizing: content-box;
padding: 2em;
max-width: 972px;
}",
".rheroicons {
width: 75px;
height: 75px;
}",
".rheroicons-solid {
fill: #2C497F;
}",
".circle-icons {
stroke: #417B5A;
}",
".rheroicons-home-modern.rheroicons-outline {
width: 44px;
height: 44px;
}"
)
),$main(
tags$h2("My Shiny App"),
tags$p("This is my cool Shiny application. Check out some of the icons"),
tags$div(
tags::rheroicon(name = "arrow-down-circle", class="circle-icons"),
rheroicons::rheroicon(name = "arrow-up-circle", class="circle-icons"),
rheroicons::rheroicon(name = "arrow-left-circle", class="circle-icons"),
rheroicons::rheroicon(name = "arrow-right-circle", class="circle-icons")
rheroicons
),$div(
tags::rheroicon(name = "musical-note", type = "solid"),
rheroicons::rheroicon(name = "musical-note")
rheroicons
),$div(
tags::rheroicon(name = "home-modern", type = "solid"),
rheroicons::rheroicon(name = "home-modern")
rheroicons
)
)
)
<- function(input, output) { }
server shinyApp(ui, server)