Title: | Empty State Components for 'Shiny' |
---|---|
Description: | Offers a comprehensive solution for managing 'empty states' in 'Shiny' applications. It provides tools to create both default and customizable components for scenarios where data is absent or doesn't match user-defined filters. The package prioritizes user experience, ensuring clarity and consistency even when data is not available to display. |
Authors: | Ryszard Szymański [aut, cre], Recle Vibal [aut], Harsh Verma [ctb], Vedha Viyash [ctb] |
Maintainer: | Ryszard Szymański <[email protected]> |
License: | LGPL-3 |
Version: | 0.1.0 |
Built: | 2024-10-15 04:15:45 UTC |
Source: | https://github.com/appsilon/shiny.emptystate |
Default empty state component, used when user doesn't provide any value while initializing new EmptyStateManager object.
default_empty_state_component()
default_empty_state_component()
a shiny.tag.
Function to create a custom empty state component.
empty_state_component(content, title, subtitle = NULL)
empty_state_component(content, title, subtitle = NULL)
content |
An HTML tag object used to render and provide the main content for the empty state. |
title |
A character string representing the main text that describes the empty state content. |
subtitle |
A character string providing supporting
details about the empty state. Defaults to |
content
works best with fontawesome::fa()
and bsicons::bs_icon()
.
shiny::icon()
will also work, but this will require loading the
html dependencies in the ui, i.e. calling fontawesome::fa_html_dependency()
to use icons from FontAwesome.Glyphicon does not need any html dependency.
a shiny.tag
library(shiny.emptystate) if (interactive()) { empty_state_component( fontawesome::fa(name = "clipboard-question", height = "10rem"), title = "Content is not available", subtitle = "Please provide valid inputs to generate content." ) empty_state_component( bsicons::bs_icon( name = "question-square", size = "15rem" ), title = "Content is not available", subtitle = "Please provide valid inputs to generate content." ) }
library(shiny.emptystate) if (interactive()) { empty_state_component( fontawesome::fa(name = "clipboard-question", height = "10rem"), title = "Content is not available", subtitle = "Please provide valid inputs to generate content." ) empty_state_component( bsicons::bs_icon( name = "question-square", size = "15rem" ), title = "Content is not available", subtitle = "Please provide valid inputs to generate content." ) }
Creates an EmptyStateManager to then show or hide content.
Creates an object to show an empty state content on selected id specified by id
parameter.
Then show
or hide
or use is_empty_state_show
to check the status.
EmptyStateManager R6 class
new()
Creates a new empty state manager object.
EmptyStateManager$new( id, html_content = default_empty_state_component(), color = NULL )
id
id of element which should be covered with html_content
html_content
Content for empty state.
Defaults to default_empty_state_component()
color
Background color of empty state content.
Defaults to NULL
A new EmptyStateManager
R6 class object.
is_empty_state_show()
Returns the current visibility state of the empty state UI.
Defaults to FALSE
EmptyStateManager$is_empty_state_show()
boolean, TRUE
/FALSE
show()
Show empty state component.
EmptyStateManager$show()
Nothing, it changes state of empty state
hide()
Hides empty state component.
EmptyStateManager$hide()
Nothing, it changes state of empty state
clone()
The objects of this class are cloneable with this method.
EmptyStateManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
library(shiny) library(shiny.emptystate) library(fontawesome) ui <- fluidPage( use_empty_state(), actionButton("show", "Show empty state!"), actionButton("hide", "Hide empty state!"), tableOutput("my_table") ) server <- function(input, output) { # Creating a custom empty state component empty_state_content <- empty_state_component( content = fa("eye-slash", height = "10rem", fill = "#808000"), title = "Hide empty state to see table", subtitle = "This empty state uses a FontAwesome icon." ) # Initialize a new empty state manager object manager_object <- EmptyStateManager$new( id = "my_table", html_content = empty_state_content ) observeEvent(input$show, { # Show empty state manager_object$show() }) observeEvent(input$hide, { # Hide empty state manager_object$hide() }) output$my_table <- renderTable(mtcars) } if (interactive()) { shinyApp(ui = ui, server = server) }
library(shiny) library(shiny.emptystate) library(fontawesome) ui <- fluidPage( use_empty_state(), actionButton("show", "Show empty state!"), actionButton("hide", "Hide empty state!"), tableOutput("my_table") ) server <- function(input, output) { # Creating a custom empty state component empty_state_content <- empty_state_component( content = fa("eye-slash", height = "10rem", fill = "#808000"), title = "Hide empty state to see table", subtitle = "This empty state uses a FontAwesome icon." ) # Initialize a new empty state manager object manager_object <- EmptyStateManager$new( id = "my_table", html_content = empty_state_content ) observeEvent(input$show, { # Show empty state manager_object$show() }) observeEvent(input$hide, { # Hide empty state manager_object$hide() }) output$my_table <- renderTable(mtcars) } if (interactive()) { shinyApp(ui = ui, server = server) }
Empty state dependencies to include anywhere in your UI but ideally at the top.
use_empty_state()
use_empty_state()
a html_dependency object
library(shiny) library(shiny.emptystate) if (interactive()) { ui <- fluidPage( use_empty_state(), dataTableOutput("my_table") ) }
library(shiny) library(shiny.emptystate) if (interactive()) { ui <- fluidPage( use_empty_state(), dataTableOutput("my_table") ) }