| Title: | Add Extra 'Fomantic UI' Components to 'shiny.semantic' |
|---|---|
| Description: | Extend 'shiny.semantic' with extra 'Fomantic UI' components. Create pages in a format similar to 'shiny', form validation and more. |
| Authors: | Ashley Baldry [aut, cre] |
| Maintainer: | Ashley Baldry <[email protected]> |
| License: | MIT + file LICENCE |
| Version: | 0.1.0 |
| Built: | 2026-05-11 06:37:32 UTC |
| Source: | https://github.com/ashbaldry/fomantic.plus |
Add a tooltip to an element that on hover will show extra information
addTooltip will only use a basic CSS tooltip with a limited amount of functionality, whereas addPopup
is initialised with JS, and can include more functionality
addPopup( el, text, position = NULL, variation = NULL, inverted = FALSE, title = NULL, offset = NULL, settings = NULL, html = FALSE ) addTooltip(el, text, position = NULL, variation = NULL, inverted = FALSE)addPopup( el, text, position = NULL, variation = NULL, inverted = FALSE, title = NULL, offset = NULL, settings = NULL, html = FALSE ) addTooltip(el, text, position = NULL, variation = NULL, inverted = FALSE)
el |
A UI element that the tooltip will be applied to |
text |
Contents of the tooltip. Can either be a character string or an HTML object |
position |
(Optional) Force the popup to appear in a direction relative to |
variation |
(Optional) Add certain features to the popup
|
inverted |
Should the colours of the popup be inverted? |
title |
(Optional) Add a title to the popup. Only appears when |
offset |
(Optional) A numeric value of the number of pixel to offset the tooltip by |
settings |
Named list of settings to be applied to the popup. Check Fomantic UI website for full list.
For example |
html |
Is |
addTooltip will return el with extra attributes added to the top level tag.
addPopup will return a shiny.tag.list, first similar to addTooltip an updated
version of el. Then a small JS script has been added to enable the popup.
https://fomantic-ui.com/modules/popup.html
addPopup( fui_el$label(id = "help_label", class = "small circular", "?"), "This can be used as a help icon in a shiny app", inverted = TRUE ) addTooltip( fui_el$label(class = "small circular", "?"), "This can be used as a help icon in a shiny app" )addPopup( fui_el$label(id = "help_label", class = "small circular", "?"), "This can be used as a help icon in a shiny app", inverted = TRUE ) addTooltip( fui_el$label(class = "small circular", "?"), "This can be used as a help icon in a shiny app" )
Add a toggle to the shiny application that triggers all Fomantic UI elements to become "inverted"
darkmode_toggle(label = "Dark Mode", ..., checked = FALSE)darkmode_toggle(label = "Dark Mode", ..., checked = FALSE)
label |
Labels to add before and after the toggle. By default "Dark Mode" will appear after the toggle |
... |
Tag attributes (named arguments) and children (unnamed arguments) |
checked |
Should the application start off in dark mode? |
To prevent elements from becoming inverted/removing their inverted state, include keep-inverted-state to
maintain them in either standard or inverted.
A shiny.tag that will provide a toggle style checkbox in the UI of a shiny application.
if (interactive()) { library(shiny) library(shiny.semantic) ui <- semanticPage( extendShinySemantic(), fui_el$grid( fui_el$row( class = "two column", fui_el$column( fui_el$segment( class = "purple", darkmode_toggle() ) ), fui_el$column( fui_el$segment( class = "red keep-inverted-state" ) ) ) ), fui_el$cards( class = "two", fui_el$card(), fui_el$card() ) ) server <- function(input, output, session) {} shiny::shinyApp(ui, server) }if (interactive()) { library(shiny) library(shiny.semantic) ui <- semanticPage( extendShinySemantic(), fui_el$grid( fui_el$row( class = "two column", fui_el$column( fui_el$segment( class = "purple", darkmode_toggle() ) ), fui_el$column( fui_el$segment( class = "red keep-inverted-state" ) ) ) ), fui_el$cards( class = "two", fui_el$card(), fui_el$card() ) ) server <- function(input, output, session) {} shiny::shinyApp(ui, server) }
fomantic.plus Dependencies to shiny.semantic ApplicationIn order for any of the fomantic.plus functionality to work
This will be automatically included in any xxx_page function in this package,
for example navbar_page.
extendShinySemantic()extendShinySemantic()
A shiny.tag.list containing tags to enable the JS and CSS required for this package.
if (interactive()) { library(shiny) library(shiny.semantic) library(fomantic.plus) ui <- semanticPage( title = "Hello Fomantic UI", tags$head( extendShinySemantic() ) ) }if (interactive()) { library(shiny) library(shiny.semantic) library(fomantic.plus) ui <- semanticPage( title = "Hello Fomantic UI", tags$head( extendShinySemantic() ) ) }
A field validation assigns a series of rules that have been assigned to a particular input and checks, upon the form submission, whether or not the input meets all specified criteria.
field_validation(id, ..., extra_params = NULL) field_rule(rule, prompt = NULL, value = NULL)field_validation(id, ..., extra_params = NULL) field_rule(rule, prompt = NULL, value = NULL)
id |
HTML id of the field to be validated |
... |
A series of |
extra_params |
A named list of extra parameters that can be added to the field validation. For example
|
rule |
The type of rule to be applied. Valid rules are available in Details. |
prompt |
Text to be displayed in the UI if the validation fails. Leave |
value |
Certain fields require a value to check validation. Check Details if the |
If it fails, then the field will be highlighted and the failures will either be specified as a message below the field or a label. Once the failure(s) has been rectified, the highlighting will disappear.
The following rules are allowed:
emptyA field is not empty
checkedA checkbox field is checked
emailA field is a valid e-mail address
urlA field is a url
integerA field is an integer value or matches an integer range*
decimalA field must be a decimal number or matches a decimal range*
numberA field is any number or matches a number range*
regExpMatches against a regular expression
creditCardA field is a valid credit card**
contains, doesntContain
A field (doesn't) contain text (case insensitive)
containsExactly, doesntContainExactly
A field (doesn't) contain text (case sensitive)
is, not
A field is (not) a value (case insensitive)
isExactly, notExactly
A field is (not) a value (case sensitive)
minLength, exactLength, maxLength
A field is at least/exactly/at most a set length
match, different
A field should (not) match the value of another validation field. Use the field ID as the value
minCount, exactCount, maxCount
A multiple select field contains at least/exactly/at most a set number of selections
* For ranges, include the parameter value = "x..y"
where x is the minimum value and y is the maximum value.
Leave either side blank to not have a lower/upper limit
** Include comma separated string of card providers if required e.g. value = "visa,mastercard"
A structured list of the field_rules that can be recognised by form_validation.
https://fomantic-ui.com/behaviors/form.html
# E-mail validations field_validation("email", field_rule("email")) # Password validation field_validation( "password", field_rule("empty"), field_rule("minLength", value = 8), field_rule("regExp", "Must contain at least one special character", "\\W") )# E-mail validations field_validation("email", field_rule("email")) # Password validation field_validation( "password", field_rule("empty"), field_rule("minLength", value = 8), field_rule("regExp", "Must contain at least one special character", "\\W") )
Creates a button specifically for Fomantic UI forms in order to check all inputs meet validation rules
form_button(input_id, label, icon = NULL, width = NULL, ...)form_button(input_id, label, icon = NULL, width = NULL, ...)
input_id |
The input slot that will be used to access the value |
label |
The contents of the button, can either be character string or HTML tags |
icon |
An optional |
width |
Width of the input |
... |
Named attributes to be applied to the button or remaining parameters passed to button, like |
A shiny.tag that will show a submit button in the UI of a shiny application.
form_validation, action_button
form_button("submit", "Submit")form_button("submit", "Submit")
A form validation behaviour checks data against a set of criteria before passing it along to the server.
form_validation( id, ..., submit_label = "Submit", submit_class = "", include_button = TRUE, inline = FALSE )form_validation( id, ..., submit_label = "Submit", submit_class = "", include_button = TRUE, inline = FALSE )
id |
ID of the parent form |
... |
A series of |
submit_label |
Label to give the submission button at the end of the form (included in returned UI with input
value |
submit_class |
Additional classes to give the submission button |
include_button |
Logical, should the submit button be included? Defaults to |
inline |
Logical, do you want the field validation errors as in-line labels ( |
In order for the validation to work, the form_validation must be a direct child of the form.
The "Submit" button has an input value of {id}_submit and will only trigger
server-side events if all the fields pass validation.
NB If you do not include either form validation input as part of the server-side code then the inputs will pass through to the server as if there were no validation.
A shiny.tag.list containing the inline JS to perform the form validation in the shiny UI.
If include_button = TRUE then a button will also be included to appear in the UI.
https://fomantic-ui.com/behaviors/form.html
if (interactive()) { library(shiny) library(shiny.semantic) library(fomantic.plus) ui <- semanticPage( tags$head( extendShinySemantic() ), form( id = "form", field( tags$label("Name"), text_input("name") ), field( tags$label("E-Mail"), text_input("email") ), form_validation( id = "form", field_validation("name", field_rule("empty")), field_validation("email", field_rule("empty"), field_rule("email")) ) ) ) server <- function(input, output) { } shinyApp(ui, server) }if (interactive()) { library(shiny) library(shiny.semantic) library(fomantic.plus) ui <- semanticPage( tags$head( extendShinySemantic() ), form( id = "form", field( tags$label("Name"), text_input("name") ), field( tags$label("E-Mail"), text_input("email") ), form_validation( id = "form", field_validation("name", field_rule("empty")), field_validation("email", field_rule("empty"), field_rule("email")) ) ) ) server <- function(input, output) { } shinyApp(ui, server) }
Create an R object that represents a Fomantic UI Element e.g. segment or container. The contents have remained as minimal as possible to enable the greatest possible flexibility.
fui_elfui_el
An object of class list of length 41.
Most of the elements work just like a standard HTML tag with some pre-defined classes, however there are a few elements which require a value, and so have an extra argument attached:
emojiFUI Element: emoji - The string of the emoji name
countryFUI Element: flag - Either the country name or 2 character ISO code
iconFUI Element: icon - The space separated name of the Font Awesome icon
html_tagFUI Elements: header, list, item - For certain elements, multiple HTML tags can be used.
The default is set to div, but can be set to any valid HTML tag.
https://fomantic-ui.com for styling Fomantic UI elements, builder
# List fui_el$list( fui_el$item("Item 1"), fui_el$item("Item 2"), fui_el$item("Item 3") ) # Pink Segment fui_el$segment( class = "pink" ) # Grid fui_el$grid( fui_el$row( class = "two column", fui_el$column(), fui_el$column() ) ) # Flag fui_el$flag("fr") # Icon fui_el$icon("exclamation triangle")# List fui_el$list( fui_el$item("Item 1"), fui_el$item("Item 2"), fui_el$item("Item 3") ) # Pink Segment fui_el$segment( class = "pink" ) # Grid fui_el$grid( fui_el$row( class = "two column", fui_el$column(), fui_el$column() ) ) # Flag fui_el$flag("fr") # Icon fui_el$icon("exclamation triangle")
Run Fomantic Plus Examples
runFPlusExample( example = NA, port = getOption("shiny.port"), launch.browser = getOption("shiny.launch.browser", interactive()), host = getOption("shiny.host", "127.0.0.1"), display.mode = c("auto", "normal", "showcase") )runFPlusExample( example = NA, port = getOption("shiny.port"), launch.browser = getOption("shiny.launch.browser", interactive()), host = getOption("shiny.host", "127.0.0.1"), display.mode = c("auto", "normal", "showcase") )
example |
The name of the example to run, or |
port |
The TCP port that the application should listen on. If the port is not specified, and the shiny.port option is set (with options(shiny.port = XX)), then that port will be used. Otherwise, use a random port between 3000:8000, excluding ports that are blocked by Google Chrome for being considered unsafe: 3659, 4045, 5060, 5061, 6000, 6566, 6665:6669 and 6697. Up to twenty random ports will be tried. |
launch.browser |
If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in interactive sessions only. |
host |
The IPv4 address that the application should listen on. Defaults to the shiny.host option, if set, or "127.0.0.1" if not. |
display.mode |
The mode in which to display the example. Defaults to |
If example = NA then a list of the available examples will be shown, otherwise the selected
application will be rendered.
if (interactive()) { runFPlusExample() # Fomantic UI Kitchen Sink runKitchenSink() }if (interactive()) { runFPlusExample() # Fomantic UI Kitchen Sink runKitchenSink() }
Dynamically show or hide a tab_panel or navbar_menu
show_tab(session = shiny::getDefaultReactiveDomain(), id, target) hide_tab(session = shiny::getDefaultReactiveDomain(), id, target)show_tab(session = shiny::getDefaultReactiveDomain(), id, target) hide_tab(session = shiny::getDefaultReactiveDomain(), id, target)
session |
The |
id |
The id of the navbar object |
target |
The tab value to toggle visibility |
Changes to the visibility of a tab in the shiny UI.
if (interactive()) { library(shiny) library(shiny.semantic) ui <- navbar_page( title = "App Title", id = "navbar", tab_panel( "Plot", action_button("hide", "Hide Table"), action_button("show", "Show Table"), value = "plot" ), tab_panel("Summary", value = "summary"), tab_panel("Table", value = "table") ) server <- function(input, output, session) { observeEvent(input$hide, hide_tab(session, "navbar", "table")) observeEvent(input$show, show_tab(session, "navbar", "table")) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(shiny.semantic) ui <- navbar_page( title = "App Title", id = "navbar", tab_panel( "Plot", action_button("hide", "Hide Table"), action_button("show", "Show Table"), value = "plot" ), tab_panel("Summary", value = "summary"), tab_panel("Table", value = "table") ) server <- function(input, output, session) { observeEvent(input$hide, hide_tab(session, "navbar", "table")) observeEvent(input$show, show_tab(session, "navbar", "table")) } shinyApp(ui, server) }
Create a tab panel
tab_panel( title, ..., value = title, icon = NULL, type = "bottom attached segment" )tab_panel( title, ..., value = title, icon = NULL, type = "bottom attached segment" )
title |
Display title for tab |
... |
UI elements to include within the tab |
value |
The value that should be sent when |
icon |
Optional icon to appear on the tab.
This attribute is only valid when using a |
type |
Change depending what type of tab is wanted. Default is |
A tab that can be passed to navbar_menu.
navbar_menu( tab_panel("Plot", shiny::plotOutput("plot")), tab_panel("Summary", shiny::verbatimTextOutput("summary")), tab_panel("Table", shiny::tableOutput("table")) )navbar_menu( tab_panel("Plot", shiny::plotOutput("plot")), tab_panel("Summary", shiny::verbatimTextOutput("summary")), tab_panel("Table", shiny::tableOutput("table")) )