Title: | A Shiny Dashboard Template System |
---|---|
Description: | A template system based on 'AdminLTE3' (<https://adminlte.io/themes/v3/>) theme. Comes with default theme that can be easily customized. Developers can upload modified templates on 'Github', and users can easily download templates with 'RStudio' project wizard. The key features of the default template include light and dark theme switcher, resizing graphs, synchronizing inputs across sessions, new notification system, fancy progress bars, and card-like flip panels with back sides, as well as various of 'HTML' tool widgets. |
Authors: | Zhengjia Wang [cph, aut, cre] , ColorlibHQ [cph] (AdminLTE - Bootstrap 4 Admin Dashboard), Bootstrap contributors [ctb] (Bootstrap library), Twitter, Inc [cph] (Bootstrap library), Ivan Sagalaev [ctb, cph] (highlight.js library), Rene Haas [ctb, cph] (OverlayScrollbars library), Zeno Rocha [ctb, cph] (Clipboard.js library) |
Maintainer: | Zhengjia Wang <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.6 |
Built: | 2024-12-13 03:11:40 UTC |
Source: | https://github.com/dipterix/shidashi |
Generates an 'accordion' tab-set that only one tab is expanded at a time. This feature is experimental and has bugs in some situations. Please use it at your own risk.
accordion( ..., id = rand_string(prefix = "accordion-"), class = NULL, style_header = NULL, style_body = NULL, env = parent.frame(), extras = list(), root_path = template_root() ) accordion_operate( id, itemId, item_title, method = c("expand", "collapse", "toggle"), session = shiny::getDefaultReactiveDomain() )
accordion( ..., id = rand_string(prefix = "accordion-"), class = NULL, style_header = NULL, style_body = NULL, env = parent.frame(), extras = list(), root_path = template_root() ) accordion_operate( id, itemId, item_title, method = c("expand", "collapse", "toggle"), session = shiny::getDefaultReactiveDomain() )
... |
'accordion' items, generated by |
id |
the element id, must be unique |
class |
the additional 'HTML' class |
style_header |
additional 'CSS' styles for header |
style_body |
additional 'CSS' styles for content body |
env |
environment to evaluate |
extras |
key-value pairs that overrides the parameters in
|
root_path |
see |
itemId |
|
item_title |
|
method |
operation, choices are |
session |
|
'shiny.tag.list'
'HTML' tags
if(interactive()) { library(shiny) library(shidashi) accordion( id = "input-set", accordion_item( title = "Input Group A", textInput("input_1", "Input 1"), collapsed = FALSE, footer = "Anim pariatur cliche reprehenderit dolor brunch." ), accordion_item( title = "Input Group B", textInput("input_2", "Input 2"), footer = actionButton("btn1", "OK"), collapsed = FALSE ) ) }
if(interactive()) { library(shiny) library(shidashi) accordion( id = "input-set", accordion_item( title = "Input Group A", textInput("input_1", "Input 1"), collapsed = FALSE, footer = "Anim pariatur cliche reprehenderit dolor brunch." ), accordion_item( title = "Input Group B", textInput("input_2", "Input 2"), footer = actionButton("btn1", "OK"), collapsed = FALSE ) ) }
'Accordion' items
accordion_item( title, ..., footer = NULL, class = "", collapsed = TRUE, parentId = rand_string(prefix = "accordion-"), itemId = rand_string(prefix = "accordion-item-"), style_header = NULL, style_body = NULL, root_path = template_root() )
accordion_item( title, ..., footer = NULL, class = "", collapsed = TRUE, parentId = rand_string(prefix = "accordion-"), itemId = rand_string(prefix = "accordion-item-"), style_header = NULL, style_body = NULL, root_path = template_root() )
title |
character title to show in the header |
... |
body content |
footer |
footer element, hidden if |
class |
the class of the item |
collapsed |
whether collapsed at the beginning |
parentId |
parent |
itemId |
the item id |
style_header , style_body
|
'CSS' style of item header and body |
root_path |
see |
'shiny.tag.list'
'HTML' tags
Only works in template framework provided by 'shidashi' package,
see use_template
add_class(selector, class, session = shiny::getDefaultReactiveDomain()) remove_class(selector, class, session = shiny::getDefaultReactiveDomain())
add_class(selector, class, session = shiny::getDefaultReactiveDomain()) remove_class(selector, class, session = shiny::getDefaultReactiveDomain())
selector |
'CSS' selector |
class |
class to add or to remove from selected elements |
session |
shiny session |
No value is returned
server <- function(input, output, session){ # Add class `hidden` to element with ID `elemid` add_class("#elemid", "hidden") # Remove class `hidden` from element with class `shiny-input-optional` remove_class(".shiny-input-optional", "hidden") }
server <- function(input, output, session){ # Add class `hidden` to element with ID `elemid` add_class("#elemid", "hidden") # Remove class `hidden` from element with class `shiny-input-optional` remove_class(".shiny-input-optional", "hidden") }
These functions should be called in 'HTML' templates. Please see vignettes for details.
adminlte_ui(root_path = template_root()) adminlte_sidebar( root_path = template_root(), settings_file = "modules.yaml", shared_id = rand_string(26) )
adminlte_ui(root_path = template_root()) adminlte_sidebar( root_path = template_root(), settings_file = "modules.yaml", shared_id = rand_string(26) )
root_path |
the root path of the website project; see
|
settings_file |
the settings file containing the module information |
shared_id |
a shared identification by session to synchronize the inputs; assigned internally. |
'HTML' tags
Usually used along with card
,
card2
, and card_tabset
. See tools
parameters in these functions accordingly.
as_badge(badge = NULL)
as_badge(badge = NULL)
badge |
characters, |
When badge
is NULL
or empty, then as_badge
returns empty strings. When badge
is a "shiny.tag"
object,
then 'HTML' class 'right'
and 'badge'
will be appended.
When badge
is a string, it should follow the syntax of
"message|class"
. The text before "|"
will be the badge
message, and the text after the "|"
becomes the class string.
'HTML' tags
# Basic usage as_badge("New") # Add class `bg-red` and `no-padding` as_badge("New|bg-red no-padding")
# Basic usage as_badge("New") # Add class `bg-red` and `no-padding` as_badge("New|bg-red no-padding")
Convert characters, shiny icons into 'fontawesome' 4
as_icon(icon = NULL, class = "fas")
as_icon(icon = NULL, class = "fas")
icon |
character or |
class |
icon class; change this when you are using 'fontawesome'
professional version. The choices are |
'HTML' tag
if(interactive()){ as_icon("bookmark", class = "far") as_icon("bookmark", class = "fas") # no icon as_icon(NULL) }
if(interactive()){ as_icon("bookmark", class = "far") as_icon("bookmark", class = "fas") # no icon as_icon(NULL) }
This function is a template function that should be called
in 'HTML' templates before closing the "</body>"
tag.
back_top_button(icon = "chevron-up", title = "Jump to")
back_top_button(icon = "chevron-up", title = "Jump to")
icon |
the icon for back-to-top button |
title |
the expanded menu title |
'HTML' tags
back_top_button() back_top_button("rocket")
back_top_button() back_top_button("rocket")
Card-like 'HTML' element
card( title, ..., footer = NULL, tools = NULL, inputId = NULL, class = "", class_header = "", class_body = "", class_foot = "", style_header = NULL, style_body = NULL, start_collapsed = FALSE, resizable = FALSE, root_path = template_root() ) card2( title, body_main, body_side = NULL, footer = NULL, tools = NULL, inputId = NULL, class = "", class_header = "", class_body = "min-height-400", class_foot = "", style_header = NULL, style_body = NULL, start_collapsed = FALSE, root_path = template_root() ) card2_open(inputId, session = shiny::getDefaultReactiveDomain()) card2_close(inputId, session = shiny::getDefaultReactiveDomain()) card2_toggle(inputId, session = shiny::getDefaultReactiveDomain()) card_operate( inputId, title, method, session = shiny::getDefaultReactiveDomain() )
card( title, ..., footer = NULL, tools = NULL, inputId = NULL, class = "", class_header = "", class_body = "", class_foot = "", style_header = NULL, style_body = NULL, start_collapsed = FALSE, resizable = FALSE, root_path = template_root() ) card2( title, body_main, body_side = NULL, footer = NULL, tools = NULL, inputId = NULL, class = "", class_header = "", class_body = "min-height-400", class_foot = "", style_header = NULL, style_body = NULL, start_collapsed = FALSE, root_path = template_root() ) card2_open(inputId, session = shiny::getDefaultReactiveDomain()) card2_close(inputId, session = shiny::getDefaultReactiveDomain()) card2_toggle(inputId, session = shiny::getDefaultReactiveDomain()) card_operate( inputId, title, method, session = shiny::getDefaultReactiveDomain() )
title |
the title of the card |
... |
the body content of the card |
footer |
the footer of the card; will be hidden if
|
tools |
a list of tools or badges to be displayed at
top-right corner, generated by |
inputId |
the id of the card |
class |
the 'HTML' class of the entire card |
class_header |
the the 'HTML' class of the card header |
class_body |
the the 'HTML' class of the card body |
class_foot |
the the 'HTML' class of the card footer |
style_header |
'CSS' style of the header |
style_body |
'CSS' style of the body |
start_collapsed |
whether the card starts as collapsed |
resizable |
whether the card body can be resized vertically; notice that if true, then the default padding for body will be zero |
root_path |
see |
body_main , body_side
|
used by |
session |
shiny session domain |
method |
action to expand, minimize, or remove the cards;
choices are |
'HTML' tags
library(shiny) library(shidashi) # Used for example only ns <- I session <- MockShinySession$new() # -------------- Basic usage ------------- card( title = "Badges", div( class = "padding-20", p( "Add badges to the top-right corder. ", "Use \"|\" to indicate the badge classes; ", "for example: \"badge-info\", \"badge-warning\"..." ), hr(), p( "Use `resizable = TRUE` to make card resizable." ) ), tools = list( as_badge("New|badge-info"), as_badge("3|badge-warning") ), class_body = "height-300", resizable = TRUE ) # ---------------- With tools ----------------- card( title = "Default Tools", plotOutput( ns("card_defaulttool_plot"), height = "100%" ), tools = list( card_tool( widget = "link", href = "https://github.com/dipterix" ), card_tool(widget = "collapse"), card_tool(widget = "maximize") ), class_body = "height-300", resizable = TRUE ) # -------------- Card2 example -------------- card2( title = "Card2 Example", body_main = plotOutput( outputId = ns("card2_plot"), height = "100%" ), body_side = fluidRow( column( 6L, textInput( ns("card2_plot_title"), "Plot title" ) ), column( 6L, sliderInput( ns("card2_plot_npts"), "# of points", min = 1, max = 100, value = 10, step = 1, round = TRUE ) ) ), tools = list( card_tool(widget = "link", href = "https://github.com/dipterix"), card_tool(widget = "collapse"), card_tool(widget = "maximize") ), class_body = "height-300" )
library(shiny) library(shidashi) # Used for example only ns <- I session <- MockShinySession$new() # -------------- Basic usage ------------- card( title = "Badges", div( class = "padding-20", p( "Add badges to the top-right corder. ", "Use \"|\" to indicate the badge classes; ", "for example: \"badge-info\", \"badge-warning\"..." ), hr(), p( "Use `resizable = TRUE` to make card resizable." ) ), tools = list( as_badge("New|badge-info"), as_badge("3|badge-warning") ), class_body = "height-300", resizable = TRUE ) # ---------------- With tools ----------------- card( title = "Default Tools", plotOutput( ns("card_defaulttool_plot"), height = "100%" ), tools = list( card_tool( widget = "link", href = "https://github.com/dipterix" ), card_tool(widget = "collapse"), card_tool(widget = "maximize") ), class_body = "height-300", resizable = TRUE ) # -------------- Card2 example -------------- card2( title = "Card2 Example", body_main = plotOutput( outputId = ns("card2_plot"), height = "100%" ), body_side = fluidRow( column( 6L, textInput( ns("card2_plot_title"), "Plot title" ) ), column( 6L, sliderInput( ns("card2_plot_npts"), "# of points", min = 1, max = 100, value = 10, step = 1, round = TRUE ) ) ), tools = list( card_tool(widget = "link", href = "https://github.com/dipterix"), card_tool(widget = "collapse"), card_tool(widget = "maximize") ), class_body = "height-300" )
To insert, remove, or active card panels, see
card_tabset_operate
.
card_tabset( ..., inputId = rand_string(prefix = "tabset-"), title = NULL, names = NULL, active = NULL, tools = NULL, footer = NULL, class = "", class_header = "", class_body = "", class_foot = "" )
card_tabset( ..., inputId = rand_string(prefix = "tabset-"), title = NULL, names = NULL, active = NULL, tools = NULL, footer = NULL, class = "", class_header = "", class_body = "", class_foot = "" )
... |
'HTML' tags; each tag will be placed into a card |
inputId |
the id of the card-set, must start with letters |
title |
the title of the card-set |
names |
title of the tabs |
active |
the title that will be active on load |
tools |
a list of tools or badges generated by
|
footer |
the footer element of the card-set |
class |
the 'HTML' class the of card-set |
class_header , class_body , class_foot
|
additional 'HTML' class the of card header, body, and footer accordingly |
'HTML' tags
library(shiny) library(shidashi) # Fake session to operate on card_tabset without shiny session <- MockShinySession$new() card_tabset( inputId = "card_set", title = "Cardset with Tools", `Tab 1` = p("Tab content 1"), class_body = "height-500", tools = list( as_badge( "New|badge-success" ), card_tool( widget = "collapse" ), card_tool( widget = "maximize" ) ) ) card_tabset_insert( inputId = "card_set", title = "Tab 2", p("New content"), session = session ) card_tabset_activate( inputId = "card_set", title = "Tab 1", session = session ) card_tabset_remove( inputId = "card_set", title = "Tab 2", session = session )
library(shiny) library(shidashi) # Fake session to operate on card_tabset without shiny session <- MockShinySession$new() card_tabset( inputId = "card_set", title = "Cardset with Tools", `Tab 1` = p("Tab content 1"), class_body = "height-500", tools = list( as_badge( "New|badge-success" ), card_tool( widget = "collapse" ), card_tool( widget = "maximize" ) ) ) card_tabset_insert( inputId = "card_set", title = "Tab 2", p("New content"), session = session ) card_tabset_activate( inputId = "card_set", title = "Tab 1", session = session ) card_tabset_remove( inputId = "card_set", title = "Tab 2", session = session )
card_tabset
Add, active, or remove a card within card_tabset
card_tabset_insert( inputId, title, ..., active = TRUE, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() ) card_tabset_remove( inputId, title, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() ) card_tabset_activate( inputId, title, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() )
card_tabset_insert( inputId, title, ..., active = TRUE, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() ) card_tabset_remove( inputId, title, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() ) card_tabset_activate( inputId, title, notify_on_failure = TRUE, session = shiny::getDefaultReactiveDomain() )
inputId |
the element id of |
title |
the title of the card to insert, activate, or to remove |
... |
the content of the card |
active |
whether to set the card to be active once added |
notify_on_failure |
whether to show notifications on failure |
session |
shiny session domain |
These functions execute session$sendCustomMessage
and return
whatever value generated by that function; usually nothing.
The icons cane be displayed at header line within
accordion
, card
, card2
,
card_tabset
. See their examples.
card_tool( inputId = NULL, title = NULL, widget = c("maximize", "collapse", "remove", "flip", "refresh", "link", "custom"), icon, class = "", href = "#", target = "_blank", start_collapsed = FALSE, ... )
card_tool( inputId = NULL, title = NULL, widget = c("maximize", "collapse", "remove", "flip", "refresh", "link", "custom"), icon, class = "", href = "#", target = "_blank", start_collapsed = FALSE, ... )
inputId |
the button id, only necessary when |
title |
the tip message to show when the mouse cursor hovers on the icon |
widget |
the icon widget type; choices are |
icon |
icon to use if you are unsatisfied with the default ones |
class |
additional class for the tool icons |
href , target
|
used when |
start_collapsed |
used when |
... |
passed to the tag as attributes |
There are 7 widget
types:
"maximize"
allow the elements to maximize themselves to full-screen
"collapse"
allow the elements to collapse
"remove"
"flip"
used together with flip_box
,
to allow card body to flip over
"refresh"
refresh all shiny outputs
"link"
open a hyper-link pointing to external websites
"custom"
turn the icon into a actionButton
.
in this case, inputId
must be specified.
'HTML' tags to be included in tools
parameter in
accordion
, card
, card2
,
card_tabset
Generates outputs that can be written to clipboards with one click
clipboardOutput( outputId = rand_string(prefix = "clipboard"), message = "Copy to clipboard", clip_text = "", class = NULL, as_card_tool = FALSE ) renderClipboard( expr, env = parent.frame(), quoted = FALSE, outputArgs = list() )
clipboardOutput( outputId = rand_string(prefix = "clipboard"), message = "Copy to clipboard", clip_text = "", class = NULL, as_card_tool = FALSE ) renderClipboard( expr, env = parent.frame(), quoted = FALSE, outputArgs = list() )
outputId |
the output id |
message |
tool tip to show when mouse hovers on the element |
clip_text |
the initial text to copy to clipboards |
class |
'HTML' class of the element |
as_card_tool |
whether to make the output as |
expr |
expression to evaluate; the results will replace
|
env |
environment to evaluate |
quoted |
whether |
outputArgs |
used to replace default arguments of |
'HTML' elements that can write to clip-board once users click on them.
clipboardOutput(clip_text = "Hey there")
clipboardOutput(clip_text = "Hey there")
Generate 'HTML' tags with 'flex' layout
flex_container( ..., style = NULL, direction = c("row", "column"), wrap = c("wrap", "nowrap", "wrap-reverse"), justify = c("flex-start", "center", "flex-end", "space-around", "space-between"), align_box = c("stretch", "flex-start", "center", "flex-end", "baseline"), align_content = c("stretch", "flex-start", "flex-end", "space-between", "space-around", "center") ) flex_item( ..., size = 1, style = NULL, order = NULL, flex = as.character(size), align = c("flex-start", "flex-end", "center"), class = NULL, .class = "fill-width padding-5" ) flex_break(..., class = NULL)
flex_container( ..., style = NULL, direction = c("row", "column"), wrap = c("wrap", "nowrap", "wrap-reverse"), justify = c("flex-start", "center", "flex-end", "space-around", "space-between"), align_box = c("stretch", "flex-start", "center", "flex-end", "baseline"), align_content = c("stretch", "flex-start", "flex-end", "space-between", "space-around", "center") ) flex_item( ..., size = 1, style = NULL, order = NULL, flex = as.character(size), align = c("flex-start", "flex-end", "center"), class = NULL, .class = "fill-width padding-5" ) flex_break(..., class = NULL)
... |
for |
style |
the additional 'CSS' style for containers or inner items |
direction , wrap , justify , align_box , align_content
|
'CSS' styles for 'flex' containers |
size |
numerical relative size of the item; will be ignored if
|
order , align , flex
|
CSS' styles for 'flex' items |
class , .class
|
class to add to the elements |
'HTML' tags
x <- flex_container( style = "position:absolute;height:100vh;top:0;left:0;width:100%", flex_item(style = 'background-color:black;'), flex_item(style = 'background-color:red;') ) # You can view it via `htmltools::html_print(x)`
x <- flex_container( style = "position:absolute;height:100vh;top:0;left:0;width:100%", flex_item(style = 'background-color:black;'), flex_item(style = 'background-color:red;') ) # You can view it via `htmltools::html_print(x)`
An 'HTML' container that can flip
flip_box( front, back, active_on = c("click", "click-front", "manual"), inputId = NULL, class = NULL ) flip(inputId, session = shiny::getDefaultReactiveDomain())
flip_box( front, back, active_on = c("click", "click-front", "manual"), inputId = NULL, class = NULL ) flip(inputId, session = shiny::getDefaultReactiveDomain())
front |
'HTML' elements to show in the front |
back |
'HTML' elements to show when the box is flipped |
active_on |
the condition when a box should be flipped; choices are
|
inputId |
element 'HTML' id; must be specified if |
class |
'HTML' class |
session |
shiny session; default is current active domain |
flip_box
returns 'HTML' tags; flip
should be called
from shiny session, and returns nothing
# More examples are available in demo library(shiny) library(shidashi) session <- MockShinySession$new() flip_box(front = info_box("Side A"), back = info_box("Side B"), inputId = 'flip_box1') flip('flip_box1', session = session)
# More examples are available in demo library(shiny) library(shidashi) session <- MockShinySession$new() flip_box(front = info_box("Side A"), back = info_box("Side B"), inputId = 'flip_box1') flip('flip_box1', session = session)
R
expressions in charactersGet re-formatted R
expressions in characters
format_text_r( expr, quoted = FALSE, reformat = TRUE, width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, ... ) html_highlight_code( expr, class = NULL, quoted = FALSE, reformat = TRUE, copy_on_click = TRUE, width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, ..., hover = c("overflow-visible-on-hover", "overflow-auto") )
format_text_r( expr, quoted = FALSE, reformat = TRUE, width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, ... ) html_highlight_code( expr, class = NULL, quoted = FALSE, reformat = TRUE, copy_on_click = TRUE, width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, ..., hover = c("overflow-visible-on-hover", "overflow-auto") )
expr |
|
quoted |
whether |
reformat |
whether to reformat |
width.cutoff , indent , wrap , args.newline , blank , ...
|
passed to
|
class |
class of |
copy_on_click |
whether to copy to clipboard if user clicks on the code; default is true |
hover |
mouse hover behavior |
format_text_r
returns characters,
html_highlight_code
returns the 'HTML' tags wrapping expressions
in <pre>
tag
s <- format_text_r(print(local({a<-1;a+1}))) cat(s) x <- info_box("Message", icon = "cogs") s <- format_text_r(get_construct_string(x), width.cutoff = 15L, quoted = TRUE) cat(s)
s <- format_text_r(print(local({a<-1;a+1}))) cat(s) x <- info_box("Message", icon = "cogs") s <- format_text_r(get_construct_string(x), width.cutoff = 15L, quoted = TRUE) cat(s)
R
expression used to generate the 'HTML' tagsThis function only works on the elements generated by this package
get_construct_string(x)
get_construct_string(x)
x |
'HTML' tags |
Quoted R
expressions that can generate the 'HTML' tags
x <- info_box("Message") get_construct_string(x)
x <- info_box("Message") get_construct_string(x)
Guess the 'AdminLTE' body class for modules, used internally
guess_body_class(cls)
guess_body_class(cls)
cls |
the class string of the |
The proposed class for <body>
tag
Store the reusing 'HTML' segments in the
views
folder. This function should be used in the
'index.html'
template
include_view(file, ..., .env = parent.frame(), .root_path = template_root())
include_view(file, ..., .env = parent.frame(), .root_path = template_root())
file |
files in the template |
... |
ignored |
.env , .root_path
|
internally used |
rendered 'HTML' segments
## Not run: # in your 'index.html' file <html> <header> {{ shidashi::include_view("header.html") }} </header> <body> </body> <!-- Before closing html tag --> {{ shidashi::include_view("footer.html") }} </html> ## End(Not run)
## Not run: # in your 'index.html' file <html> <header> {{ shidashi::include_view("header.html") }} </header> <body> </body> <!-- Before closing html tag --> {{ shidashi::include_view("footer.html") }} </html> ## End(Not run)
Generates 'HTML' info box
info_box( ..., icon = "envelope", class = "", class_icon = "bg-info", class_content = "", root_path = template_root() )
info_box( ..., icon = "envelope", class = "", class_icon = "bg-info", class_content = "", root_path = template_root() )
... |
box content |
icon |
the box icon; default is |
class |
class of the box container |
class_icon |
class of the icon |
class_content |
class of the box body |
root_path |
see |
'HTML' tags
library(shiny) library(shidashi) info_box("Message", icon = "cogs") info_box( icon = "thumbs-up", span(class = "info-box-text", "Likes"), span(class = "info-box-number", "12,320"), class_icon = "bg-red" ) info_box("No icons", icon = NULL)
library(shiny) library(shidashi) info_box("Message", icon = "cogs") info_box( icon = "thumbs-up", span(class = "info-box-text", "Likes"), span(class = "info-box-number", "12,320"), class_icon = "bg-red" ) info_box("No icons", icon = NULL)
The 'JavaScript' tunnel
register_session_id( session = shiny::getDefaultReactiveDomain(), shared_id = NULL, shared_inputs = NA ) register_session_events(session = shiny::getDefaultReactiveDomain()) get_theme(event_data, session = shiny::getDefaultReactiveDomain()) get_jsevent( event_data, type, default = NULL, session = shiny::getDefaultReactiveDomain() )
register_session_id( session = shiny::getDefaultReactiveDomain(), shared_id = NULL, shared_inputs = NA ) register_session_events(session = shiny::getDefaultReactiveDomain()) get_theme(event_data, session = shiny::getDefaultReactiveDomain()) get_jsevent( event_data, type, default = NULL, session = shiny::getDefaultReactiveDomain() )
session |
shiny reactive domain |
shared_id |
the shared id of the session, usually automatically set |
shared_inputs |
the input names to share to/from other sessions |
event_data |
a reactive value list returned by
|
type |
event type; see 'Details' |
default |
default value if |
The register_session_id
should be used in the module
server function. It registers a shared_id
and a private_id
to the session. The sessions with the same shared_id
can synchronize
their inputs, specified by shared_inputs
even on different browser
tabs.
register_session_events
will read the session events from 'JavaScript'
and passively update these information. Any the event fired by
shidashi.broadcastEvent
in 'JavaScript' will be available as
reactive value. get_jsevent
provides a convenient way to read
these events provided the right
event types. get_theme
is a special get_jsevent
that with
event type "theme.changed"
.
Function register_session_id
and register_session_events
should be called at the beginning of server functions. They can be
called multiple times safely. Function
get_jsevent
and get_theme
should be called in reactive
contexts (such as observe
,
observeEvent
).
register_session_id
returns a list of function to control
"sharing" inputs with other shiny sessions with the same shared_id
.
register_session_events
returns a reactive value list that reflects
the session state.
get_jsevent
returns events fired by
shidashi.broadcastEvent
in 'JavaScript'.
get_theme
returns a list of theme, foreground, and background color.
# shiny server function library(shiny) server <- function(input, output, session){ sync_tools <- register_session_id(session = session) event_data <- register_session_events(session = session) # if you want to enable syncing. They are suspended by default sync_tools$enable_broadcast() sync_tools$enable_sync() # get_theme should be called within reactive context output$plot <- renderPlot({ theme <- get_theme(event_data) mar(bg = theme$background, fg = theme$foreground) plot(1:10) }) }
# shiny server function library(shiny) server <- function(input, output, session){ sync_tools <- register_session_id(session = session) event_data <- register_session_events(session = session) # if you want to enable syncing. They are suspended by default sync_tools$enable_broadcast() sync_tools$enable_sync() # get_theme should be called within reactive context output$plot <- renderPlot({ theme <- get_theme(event_data) mar(bg = theme$background, fg = theme$foreground) plot(1:10) }) }
Obtain the module information
module_info(root_path = template_root(), settings_file = "modules.yaml") load_module( root_path = template_root(), request = list(QUERY_STRING = "/"), env = parent.frame() )
module_info(root_path = template_root(), settings_file = "modules.yaml") load_module( root_path = template_root(), request = list(QUERY_STRING = "/"), env = parent.frame() )
root_path |
the root path of the website project |
settings_file |
the settings file containing the module information |
request |
'HTTP' request string |
env |
environment to load module variables into |
The module files are stored in modules/
folder in your
project. The folder names are the module id. Within each folder,
there should be one "server.R"
, R/
, and a
"module-ui.html"
.
The R/
folder stores R code files that generate variables,
which will be available to the other two files. These variables, along
with some built-ins, will be used to render "module-ui.html"
.
The built-in functions are
shiny name-space function; should be used to generate the id for inputs and outputs. This strategy avoids conflict id effectively.
a variable of the module id
a function that returns the module label
The "server.R"
has access to all the code in R/
as well.
Therefore it is highly recommended that you write each 'UI' component
side-by-side with their corresponding server functions and call
these server functions in "server.R"
.
A data frame with the following columns that contain the module information:
id
module id, folder name
order
display order in side-bar
group
group menu name if applicable, otherwise NA
label
the readable label to be displayed on the side-bar
icon
icon that will be displayed ahead of label, will be
passed to as_icon
badge
badge text that will be displayed
following the module label, will be passed to as_badge
url
the relative 'URL' address of the module.
library(shiny) module_info() # load master module load_module() # load specific module module_data <- load_module( request = list(QUERY_STRING = "/?module=module_id")) env <- module_data$environment if(interactive()){ # get module title env$module_title() # generate module-specific shiny id env$ns("input1") # generate part of the UI env$ui() }
library(shiny) module_info() # load master module load_module() # load specific module module_data <- load_module( request = list(QUERY_STRING = "/?module=module_id")) env <- module_data$environment if(interactive()){ # get module title env$module_title() # generate module-specific shiny id env$ns("input1") # generate part of the UI env$ui() }
The 'Bootstrap' notification
show_notification( message, title = "Notification!", subtitle = "", type = c("default", "info", "warning", "success", "danger", "white", "dark"), close = TRUE, position = c("topRight", "topLeft", "bottomRight", "bottomLeft"), autohide = TRUE, fixed = TRUE, delay = 5000, icon = NULL, collapse = "", session = shiny::getDefaultReactiveDomain(), class = NULL, ... ) clear_notifications(class = NULL, session = shiny::getDefaultReactiveDomain())
show_notification( message, title = "Notification!", subtitle = "", type = c("default", "info", "warning", "success", "danger", "white", "dark"), close = TRUE, position = c("topRight", "topLeft", "bottomRight", "bottomLeft"), autohide = TRUE, fixed = TRUE, delay = 5000, icon = NULL, collapse = "", session = shiny::getDefaultReactiveDomain(), class = NULL, ... ) clear_notifications(class = NULL, session = shiny::getDefaultReactiveDomain())
message |
notification body content, can be 'HTML' tags |
title , subtitle
|
title and subtitle of the notification |
type |
type of the notification; can be |
close |
whether to allow users to close the notification |
position |
where the notification should be; choices are
|
autohide |
whether to automatically hide the notification |
fixed |
whether the position should be fixed |
delay |
integer in millisecond to hide the notification if
|
icon |
the icon of the title |
collapse |
if |
session |
shiny session domain |
class |
the extra class of the notification, can be used for style
purposes, or by |
... |
other options; see https://adminlte.io/docs/3.1//javascript/toasts.html#options |
Both functions should be used in shiny reactive contexts. The messages will be sent to shiny 'JavaScript' interface and nothing will be returned.
## Not run: # the examples must run in shiny reactive context show_notification( message = "This validation process has finished. You are welcome to proceed.", autohide = FALSE, title = "Success!", subtitle = "type='success'", type = "success" ) show_notification( message = "This notification has title and subtitle", autohide = FALSE, title = "Hi there!", subtitle = "Welcome!", icon = "kiwi-bird", class = "notification-auto" ) # only clear notifications with class "notification-auto" clear_notifications("notification-auto") ## End(Not run)
## Not run: # the examples must run in shiny reactive context show_notification( message = "This validation process has finished. You are welcome to proceed.", autohide = FALSE, title = "Success!", subtitle = "type='success'", type = "success" ) show_notification( message = "This notification has title and subtitle", autohide = FALSE, title = "Hi there!", subtitle = "Welcome!", icon = "kiwi-bird", class = "notification-auto" ) # only clear notifications with class "notification-auto" clear_notifications("notification-auto") ## End(Not run)
For detailed usage, see demo application by
running render()
.
progressOutput( outputId, ..., description = "Initializing", width = "100%", class = "bg-primary", value = 0, size = c("md", "sm", "xs") ) renderProgress(expr, env = parent.frame(), quoted = FALSE, outputArgs = list())
progressOutput( outputId, ..., description = "Initializing", width = "100%", class = "bg-primary", value = 0, size = c("md", "sm", "xs") ) renderProgress(expr, env = parent.frame(), quoted = FALSE, outputArgs = list())
outputId |
the element id of the progress |
... |
extra elements on the top of the progress bar |
description |
descriptive message below the progress bar |
width |
width of the progress |
class |
progress class, default is |
value |
initial value, ranging from 0 to 100; default is 0 |
size |
size of the progress bar; choices are |
expr |
R expression that should return a named list of |
env |
where to evaluate |
quoted |
whether |
outputArgs |
a list of other parameters in |
progressOutput
returns 'HTML' tags containing progress bars
that can be rendered later via shiny_progress
or
renderProgress
. renderProgress
returns shiny render functions
internally.
library(shiny) library(shidashi) progressOutput("sales_report_prog1", description = "6 days left!", "Add Products to Cart", span(class="float-right", "123/150"), value = 123/150 * 100) # server function server <- function(input, output, session, ...){ output$sales_report_prog1 <- renderProgress({ return(list( value = 140 / 150 * 100, description = "5 days left!" )) }) }
library(shiny) library(shidashi) progressOutput("sales_report_prog1", description = "6 days left!", "Add Products to Cart", span(class="float-right", "123/150"), value = 123/150 * 100) # server function server <- function(input, output, session, ...){ output$sales_report_prog1 <- renderProgress({ return(list( value = 140 / 150 * 100, description = "5 days left!" )) }) }
Creates or get reactive value list that is shared within the same shiny session
register_global_reactiveValues( name, session = shiny::getDefaultReactiveDomain() )
register_global_reactiveValues( name, session = shiny::getDefaultReactiveDomain() )
name |
character, the key of the list |
session |
shiny session |
A shiny reactiveValues
object
Render a 'shidashi' project
render( root_path = template_root(), ..., prelaunch = NULL, prelaunch_quoted = FALSE, launch_browser = TRUE, as_job = TRUE, test_mode = getOption("shiny.testmode", FALSE) )
render( root_path = template_root(), ..., prelaunch = NULL, prelaunch_quoted = FALSE, launch_browser = TRUE, as_job = TRUE, test_mode = getOption("shiny.testmode", FALSE) )
root_path |
the project path, default is the demo folder from
|
... |
additional parameters passed to |
prelaunch |
expression to execute before launching the session; the expression will execute in a brand new session |
prelaunch_quoted |
whether the expression is quoted; default is false |
launch_browser |
whether to launch browser; default is |
as_job |
whether to run as 'RStudio' jobs; this options is only available when 'RStudio' is available |
test_mode |
whether to test the project; this options is helpful when you want to debug the project without relaunching shiny applications |
This functions runs a 'shiny' application, and returns the job id if 'RStudio' is available.
template_root() if(interactive()){ render() }
template_root() if(interactive()){ render() }
Forces outdated output to reset and show a silent message.
reset_output( outputId, message = "This output has been reset", session = shiny::getDefaultReactiveDomain() )
reset_output( outputId, message = "This output has been reset", session = shiny::getDefaultReactiveDomain() )
outputId |
output ID |
message |
output message |
session |
shiny reactive domain |
No value
Wrapper of shiny progress that can run without shiny
shiny_progress( title, max = 1, ..., quiet = FALSE, session = shiny::getDefaultReactiveDomain(), shiny_auto_close = FALSE, log = NULL, outputId = NULL )
shiny_progress( title, max = 1, ..., quiet = FALSE, session = shiny::getDefaultReactiveDomain(), shiny_auto_close = FALSE, log = NULL, outputId = NULL )
title |
the title of the progress |
max |
max steps of the procedure |
... |
passed to initialization method of |
quiet |
whether the progress needs to be quiet |
session |
shiny session domain |
shiny_auto_close |
whether to close the progress once function exits |
log |
alternative log function |
outputId |
the element id of |
a list of functions that controls the progress
{ progress <- shiny_progress("Procedure A", max = 10) for(i in 1:10){ progress$inc(sprintf("Step %s", i)) Sys.sleep(0.1) } progress$close() } if(interactive()){ library(shiny) ui <- fluidPage( fluidRow( column(12, actionButton("click", "Click me")) ) ) server <- function(input, output, session) { observeEvent(input$click, { progress <- shiny_progress("Procedure B", max = 10, shiny_auto_close = TRUE) for(i in 1:10){ progress$inc(sprintf("Step %s", i)) Sys.sleep(0.1) } }) } shinyApp(ui, server) }
{ progress <- shiny_progress("Procedure A", max = 10) for(i in 1:10){ progress$inc(sprintf("Step %s", i)) Sys.sleep(0.1) } progress$close() } if(interactive()){ library(shiny) ui <- fluidPage( fluidRow( column(12, actionButton("click", "Click me")) ) ) server <- function(input, output, session) { observeEvent(input$click, { progress <- shiny_progress("Procedure B", max = 10, shiny_auto_close = TRUE) for(i in 1:10){ progress$inc(sprintf("Step %s", i)) Sys.sleep(0.1) } }) } shinyApp(ui, server) }
Please write your own version. This function is designed for demo-use only.
show_ui_code( x, class = NULL, code_only = FALSE, as_card = FALSE, card_title = "", class_body = "bg-gray-70", width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, copy_on_click = TRUE, ... )
show_ui_code( x, class = NULL, code_only = FALSE, as_card = FALSE, card_title = "", class_body = "bg-gray-70", width.cutoff = 80L, indent = 2, wrap = TRUE, args.newline = TRUE, blank = FALSE, copy_on_click = TRUE, ... )
x |
'HTML' tags generated by this package |
class |
additional 'HTML' class |
code_only |
whether to show code only |
as_card |
whether to wrap results in |
card_title , class_body
|
used by |
width.cutoff , indent , wrap , args.newline , blank , copy_on_click , ...
|
passed
to |
'HTML' tags
html_highlight_code
Configure template options that are shared across the sessions
template_settings template_settings_set(...) template_settings_get(name, default = NULL) template_root()
template_settings template_settings_set(...) template_settings_get(name, default = NULL) template_root()
... |
key-value pair to set options |
name |
character, key of the value |
default |
default value if the key is missing |
An object of class list
of length 3.
The settings is designed to store static key-value pairs that
are shared across the sessions. The most important key is
"root_path"
, which should be a path pointing to the template
folder.
template_settings_get
returns the values represented by the
corresponding keys, or the default value if key is missing.
# Get current website root path template_root()
# Get current website root path template_root()
Download 'shidashi' templates from 'Github'
use_template( path, user = "dipterix", theme = "AdminLTE3", repo = "shidashi-templates", branch = "main", ... )
use_template( path, user = "dipterix", theme = "AdminLTE3", repo = "shidashi-templates", branch = "main", ... )
path |
the path to create 'shidashi' project |
user |
'Github' user name |
theme |
the theme to download |
repo |
repository if the name is other than |
branch |
branch name if other than |
... |
ignored |
To publish a 'shidashi' template, create a 'Github' repository
called 'shidashi-templates'
, or fork the built-in templates. The theme
is the sub-folder
of the template repository.
An easy way to use a template in your project is through the 'RStudio' project widget. In the 'RStudio' navigation bar, go to "File" menu, click on the "New Project..." button, select the "Create a new project" option, and find the item that creates 'shidashi' templates. Use the widget to set up template directory.
the target project path