Abstract
Creating a great user interface for your Shiny apps can be a hassle, especially if you want to work purely in R and don't want to use, for instance HTML templates. This package adds support for a powerful UI library Fomantic UI (formerly Semantic UI). It also supports universal UI input binding that works with various DOM elements.
Introduction
The R package shiny.semantic (version 0.5.1) represents a significant technical advancement for the R/Shiny ecosystem. While standard Shiny applications rely on the aging Bootstrap 3 framework, shiny.semantic provides a bridge to Fomantic UI, enabling developers to build modern, responsive, and professional user interfaces entirely within the R environment. This approach eliminates the common "UI gap" where data scientists struggle to move beyond generic layouts without deep knowledge of HTML and CSS.
Addressing the UI Gap
Standard Shiny layouts often result in a recognizable but "generic" aesthetic. Customizing these layouts typically requires significant front-end engineering. shiny.semantic addresses this by wrapping the Fomantic UI library into R functions, providing a "pure R" workflow. This allows for the creation of advanced UI elements—such as accordions, modals, and complex grid layouts—that remain fully integrated with Shiny’s reactive programming model.
Core Methodology
The package introduces several key innovations to UI development in R:
1. The semanticPage Wrapper
As a drop-in replacement for Shiny’s fluidPage, semanticPage initializes Fomantic UI dependencies. It also includes a suppress_bootstrap flag, allowing developers to opt-out of default Shiny styles to ensure a consistent aesthetic and avoid CSS conflicts.
2. CSS Grid System
The grid() and grid_template() functions allow developers to define layouts using R-native syntax. By treating the layout as a structured R object (e.g., using rbind to define named areas), the package automatically translates these definitions into modern CSS Grid code. This makes complex, responsive layouts reproducible and easier to debug.
3. Universal Input Binding
A standout feature is shiny_input(), a mechanism that allows R to communicate with arbitrary DOM elements. This enables the creation of custom inputs that extend beyond the standard Shiny library, facilitating the use of exotic web components.
The Component Ecosystem
The library's strength lies in its breadth, offering over 50 distinct UI components. These range from basic elements like buttons to advanced interactive modules like calendars, rating inputs, and multi-stage "step" workflows.
As shown in the documentation for the accordion component, the API is designed to be human-centric. Parameters like fluid, active_title, and styled allow for granular control over the component's behavior and appearance directly from R.
Similarly, standard elements like buttons are wrapped to support Semantic UI's specific attributes, such as icons and custom CSS classes, while maintaining compatibility with Shiny's input slot system.
Results and Design Philosophy
The package adheres to Fomantic UI's "natural language" philosophy, making UI code highly readable (e.g., class = "ui red ribbon label"). Key results of this implementation include:
- Responsive Design: Built-in support for mobile-specific templates via the grid system.
- Integration: Seamless compatibility with other packages, such as
DTviasemantic_DT. - Workflow Efficiency: The
steps()system provides an elegant way to handle multi-stage research pipelines.
Limitations and Future Directions
Despite its robustness, the package has some limitations. The modern CSS Grid system is not supported by the internal RStudio viewer pane, requiring users to view applications in modern web browsers. Additionally, some features, such as the width parameter in checkbox_input, are still under development. Future work likely involves wrapping more Fomantic UI modules and refining the universal binding system to support a wider array of web components.
Conclusion
shiny.semantic empowers R users to create high-quality web tools without leaving the R ecosystem. By providing a structured, data-driven approach to UI design, it lowers the barrier to entry for professional-grade dashboard development.
Summary updated