faicons
faicons is a Python library that provides an interface to Font-Awesome for use in Shiny for Python applications. It enables developers to easily embed scalable vector graphic (SVG) icons from Font Awesome 6.2.0 into their Shiny UI. The current version is 0.2.2, with releases occurring infrequently, typically for minor improvements or Font Awesome version updates.
Warnings
- gotcha The library is currently listed with a '2 - Pre-Alpha' development status on PyPI, indicating it is still in early development and APIs might be subject to change.
- gotcha The `icon_svg()` function's `height` and `width` parameters expect a numerical value followed by a CSS length unit (e.g., '100px', '2em'), not a percentage value like '100%'. Providing a percentage will raise a `ValueError`.
- gotcha faicons currently uses Font Awesome 6.2.0. Font Awesome 7.0 introduced significant breaking changes (e.g., fixed-width icons by default, changes to SVG path classes, removal of legacy webfonts). Icons and styling expectations from FA7 might not apply or work as expected with faicons.
- gotcha While faicons provides a Python interface for Font Awesome icons, it is specifically designed 'for use in Shiny for Python'. Directly generating standalone SVG strings with `icon_svg()` outside of a framework that renders HTML (like Shiny) may require additional handling to display them correctly in a web context.
Install
-
pip install faicons
Imports
- icon_svg
from faicons import icon_svg
Quickstart
from shiny import App, ui
from faicons import icon_svg
app_ui = ui.page_fluid(
ui.h2("Shiny App with faicons"),
ui.input_action_button("like_button", "Like", icon=icon_svg("thumbs-up")),
ui.input_action_button("share_button", "Share", icon=icon_svg("share-alt")),
ui.output_text("feedback"),
)
def server(input, output, session):
@ui.reactive.Effect
@ui.event(input.like_button)
def _():
ui.notification_show("You liked it!")
@ui.reactive.Effect
@ui.event(input.share_button)
def _():
ui.notification_show("You shared it!")
app = App(app_ui, server)