Title: | A Wrapper of the 'React' Library 'Chakra UI' for 'Shiny' |
---|---|
Description: | Makes the 'React' library 'Chakra UI' usable in 'Shiny' apps. 'Chakra UI' components include alert dialogs, drawers (sliding panels), menus, modals, popovers, sliders, and more. |
Authors: | Stéphane Laurent [aut, cre], Segun Adebayo [cph] ('Chakra UI' library (https://chakra-ui.com/)), David Kaye [ctb] ('json-normalize.js'), RubyLouvre [cph] ('jsx-parser' library), Terence Eden [cph] ('SuperTinyIcons' library (https://github.com/edent/SuperTinyIcons/)), Ionic (http://ionic.io/) [cph] |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.1 |
Built: | 2024-11-16 04:50:14 UTC |
Source: | https://github.com/stla/shinychakraui |
An alert dialog widget.
chakraAlertDialog( inputId, options = chakraAlertDialogOptions(), openButton, header, body, footer )
chakraAlertDialog( inputId, options = chakraAlertDialogOptions(), openButton, header, body, footer )
inputId |
widget id |
options |
named list of options created with
|
openButton |
a Chakra button to open the alert dialog |
header |
an |
body |
an |
footer |
an |
You can use an action
attribute and a value
attribute to the Chakra buttons you put in the widget. For example, if
you include the Chakra button
Tag$Button("Cancel", action = "cancel", value = "CANCEL")
, clicking
this button will cancel the alert dialog and will set the Shiny value
"CANCEL"
. Other possible action attributes are "close"
to
close the alert dialog, "disable"
to disable the alert dialog, and
"remove"
to entirely remove the widget.
A widget that can be used in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraAlertDialog( inputId = "alertDialog", openButton = Tag$Button( leftIcon = Tag$DeleteIcon(), colorScheme = "red", "Delete customer" ), header = Tag$AlertDialogHeader( fontSize = "lg", fontWeight = "bold", "Delete customer?" ), body = Tag$AlertDialogBody( "Are you sure? You can't undo this action afterwards." ), footer = Tag$AlertDialogFooter( Tag$ButtonGroup( spacing = "3", Tag$Button( action = "cancel", value = "CANCEL", "Cancel" ), Tag$Button( action = "disable", value = "DISABLE", colorScheme = "red", "Disable" ), Tag$Button( action = "remove", value = "REMOVE", "Remove" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["alertDialog"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraAlertDialog( inputId = "alertDialog", openButton = Tag$Button( leftIcon = Tag$DeleteIcon(), colorScheme = "red", "Delete customer" ), header = Tag$AlertDialogHeader( fontSize = "lg", fontWeight = "bold", "Delete customer?" ), body = Tag$AlertDialogBody( "Are you sure? You can't undo this action afterwards." ), footer = Tag$AlertDialogFooter( Tag$ButtonGroup( spacing = "3", Tag$Button( action = "cancel", value = "CANCEL", "Cancel" ), Tag$Button( action = "disable", value = "DISABLE", colorScheme = "red", "Disable" ), Tag$Button( action = "remove", value = "REMOVE", "Remove" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["alertDialog"]]) }) } if(interactive()){ shinyApp(ui, server) }
Options for the alert dialog widget
(chakraAlertDialog
).
chakraAlertDialogOptions( closeOnEsc = TRUE, colorScheme = "red", isCentered = TRUE, motionPreset = "scale", size = "md", ... )
chakraAlertDialogOptions( closeOnEsc = TRUE, colorScheme = "red", isCentered = TRUE, motionPreset = "scale", size = "md", ... )
closeOnEsc |
whether to close the modal on pressing the 'esc' key |
colorScheme |
a Chakra color scheme |
isCentered |
whether to center the modal on screen |
motionPreset |
transition that should be used for the modal; one of
|
size |
modal size, |
... |
other attributes of |
A named list, for usage in chakraAlertDialog
.
A widget with a parent checkbox and child checkboxes.
chakraCheckboxWithChildren( inputId, parentCheckbox, ..., stackAttributes = list(pl = 6, mt = 1, spacing = 1) )
chakraCheckboxWithChildren( inputId, parentCheckbox, ..., stackAttributes = list(pl = 6, mt = 1, spacing = 1) )
inputId |
widget id |
parentCheckbox |
the parent checkbox |
... |
the child checkboxes |
stackAttributes |
list of attributes which control the layout |
A widget to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraCheckboxWithChildren( "cwc", Tag$Checkbox( "Parent checkbox" ), Tag$Checkbox( "Child checkbox 1" ), Tag$Checkbox( defaultChecked = TRUE, "Child checkbox 2" ) ) ) ) server <- function(input, output, session){ observe({ print(input[["cwc"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraCheckboxWithChildren( "cwc", Tag$Checkbox( "Parent checkbox" ), Tag$Checkbox( "Child checkbox 1" ), Tag$Checkbox( defaultChecked = TRUE, "Child checkbox 2" ) ) ) ) server <- function(input, output, session){ observe({ print(input[["cwc"]]) }) } if(interactive()){ shinyApp(ui, server) }
List of Chakra color schemes (to use as a colorScheme
attribute in e.g. Chakra buttons).
chakraColorSchemes()
chakraColorSchemes()
The names of the Chakra color schemes in a vector.
chakraColorSchemes()
chakraColorSchemes()
A widget combining a slider and a number input.
chakraCombinedSlider( id, value, min, max, step = NULL, maxWidth = "400px", numericInputOptions = numberInputOptions(), spacing = "2rem", keepWithinRange = TRUE, clampValueOnBlur = TRUE, focusThumbOnChange = FALSE, trackColor = NULL, filledTrackColor = NULL, tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptions = sliderThumbOptions(), ... )
chakraCombinedSlider( id, value, min, max, step = NULL, maxWidth = "400px", numericInputOptions = numberInputOptions(), spacing = "2rem", keepWithinRange = TRUE, clampValueOnBlur = TRUE, focusThumbOnChange = FALSE, trackColor = NULL, filledTrackColor = NULL, tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptions = sliderThumbOptions(), ... )
id |
widget id |
value |
initial value |
min |
minimal value |
max |
maximal value |
step |
increment step |
maxWidth |
slider width |
numericInputOptions |
list of options for the number input created with
|
spacing |
the space between the number input and the slider |
keepWithinRange |
whether to forbid the value to exceed the max or go lower than min |
clampValueOnBlur |
similar to |
focusThumbOnChange |
whether to focus the thumb on change |
trackColor |
color of the slider track |
filledTrackColor |
color of the filled slider track |
tooltip |
whether to set a tooltip to the thumb, to show the value |
tooltipOptions |
options of the tooltip, a list created with
|
thumbOptions |
list of options for the thumb created with
|
... |
other attributes passed to |
A widget to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), br(), chakraComponent( "mycomponent", chakraCombinedSlider( "slider", value = 5, min = 0, max = 10, step = 0.5, maxWidth = "300px", tooltip = TRUE, trackColor = "green.300", thumbOptions = sliderThumbOptions( width = 20, height = 20, borderColor = "firebrick", borderWidth = "3px" ) ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), br(), chakraComponent( "mycomponent", chakraCombinedSlider( "slider", value = 5, min = 0, max = 10, step = 0.5, maxWidth = "300px", tooltip = TRUE, trackColor = "green.300", thumbOptions = sliderThumbOptions( width = 20, height = 20, borderColor = "firebrick", borderWidth = "3px" ) ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
Create a Chakra component.
chakraComponent(componentId, ...)
chakraComponent(componentId, ...)
componentId |
component id |
... |
elements to include within the component |
A Shiny widget to use in a UI definition, preferably in
chakraPage
.
Create a drawer widget, a panel that slides out from the edge of the screen.
chakraDrawer( inputId, openButton, options = chakraDrawerOptions(), isOpen = FALSE, closeButton = TRUE, header, body, footer )
chakraDrawer( inputId, openButton, options = chakraDrawerOptions(), isOpen = FALSE, closeButton = TRUE, header, body, footer )
inputId |
widget id |
openButton |
a Chakra button to open the drawer |
options |
list of options created with |
isOpen |
Boolean, whether the drawer is initially open |
closeButton |
Boolean, whether to include a closing button |
header |
a |
body |
a |
footer |
a |
Similarly to chakraAlertDialog
, you can set an
action attribute and a value attribute to the Chakra buttons you include
in the Chakra drawer.
A widget to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraDrawer( "drawer", openButton = Tag$Button("Open Drawer"), options = chakraDrawerOptions(placement = "right"), header = Tag$DrawerHeader("I'm the header"), body = Tag$DrawerBody( Tag$Box("I'm the body") ), footer = Tag$DrawerFooter( Tag$ButtonGroup( spacing = "6", Tag$Button( value = "try me", "Try me" ), Tag$Button( action = "close", variant = "outline", "Close" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["drawer"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraDrawer( "drawer", openButton = Tag$Button("Open Drawer"), options = chakraDrawerOptions(placement = "right"), header = Tag$DrawerHeader("I'm the header"), body = Tag$DrawerBody( Tag$Box("I'm the body") ), footer = Tag$DrawerFooter( Tag$ButtonGroup( spacing = "6", Tag$Button( value = "try me", "Try me" ), Tag$Button( action = "close", variant = "outline", "Close" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["drawer"]]) }) } if(interactive()){ shinyApp(ui, server) }
Options for the drawer widget
(chakraDrawer
).
chakraDrawerOptions( closeOnEsc = TRUE, closeOnOverlayClick = TRUE, colorScheme = NULL, isCentered = FALSE, isFullHeight = FALSE, motionPreset = "scale", placement = "right", size = "xs", ... )
chakraDrawerOptions( closeOnEsc = TRUE, closeOnOverlayClick = TRUE, colorScheme = NULL, isCentered = FALSE, isFullHeight = FALSE, motionPreset = "scale", placement = "right", size = "xs", ... )
closeOnEsc |
whether to close the panel on pressing the 'esc' key |
closeOnOverlayClick |
whether to close the panel on clicking the overlay |
colorScheme |
a chakra color scheme |
isCentered |
whether to center the modal on screen |
isFullHeight |
if |
motionPreset |
transition that should be used for the modal; one of
|
placement |
placement of the drawer, |
size |
modal size, |
... |
other attributes of |
A named list, for usage in chakraDrawer
.
A function to run examples of Shiny apps with Chakra components.
chakraExample(example, display.mode = "showcase", ...)
chakraExample(example, display.mode = "showcase", ...)
example |
example name |
display.mode |
the display mode to use when running the example; see
|
... |
arguments passed to |
No return value, just launches a Shiny app.
if(interactive()){ chakraExample("Menu") }
if(interactive()){ chakraExample("Menu") }
List of Chakra examples.
chakraExamples()
chakraExamples()
No return value, only prints a message listing the Chakra examples.
chakraExamples() if(interactive()){ chakraExample("MenuWithGroups") }
chakraExamples() if(interactive()){ chakraExample("MenuWithGroups") }
List of Chakra icons.
chakraIcons()
chakraIcons()
See all chakra icons.
The names of the Chakra icons in a vector.
chakraIcons()
chakraIcons()
A modal widget.
chakraModal( inputId, options = chakraModalOptions(), openButton, isOpen = FALSE, header, body, footer )
chakraModal( inputId, options = chakraModalOptions(), openButton, isOpen = FALSE, header, body, footer )
inputId |
widget id |
options |
named list of options created with
|
openButton |
a Chakra button to open the modal |
isOpen |
whether the modal is initially open |
header |
a |
body |
a |
footer |
a |
You can use an action
attribute and a value
attribute to the Chakra buttons you put in the widget. For example, if
you include the Chakra button
Tag$Button("Close", action = "close", value = "CLOSE")
, clicking
this button will close the modal and will set the Shiny value
"CLOSE"
. Other possible action attributes are "cancel"
to
cancel, "disable"
to disable the modal, and
"remove"
to entirely remove the modal.
A widget that can be used in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraModal( inputId = "modal", openButton = Tag$Button( colorScheme = "orange", "Open Modal" ), header = Tag$ModalHeader( fontSize = "lg", fontWeight = "bold", "Modal title" ), body = Tag$ModalBody( "Sit nulla est ex deserunt exercitation anim occaecat." ), footer = Tag$ModalFooter( Tag$ButtonGroup( spacing = "3", Tag$Button( action = "close", value = "CLOSE", "Close" ), Tag$Button( action = "cancel", colorScheme = "red", "Cancel" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["modal"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraModal( inputId = "modal", openButton = Tag$Button( colorScheme = "orange", "Open Modal" ), header = Tag$ModalHeader( fontSize = "lg", fontWeight = "bold", "Modal title" ), body = Tag$ModalBody( "Sit nulla est ex deserunt exercitation anim occaecat." ), footer = Tag$ModalFooter( Tag$ButtonGroup( spacing = "3", Tag$Button( action = "close", value = "CLOSE", "Close" ), Tag$Button( action = "cancel", colorScheme = "red", "Cancel" ) ) ) ) ) ) server <- function(input, output, session){ observe({ print(input[["modal"]]) }) } if(interactive()){ shinyApp(ui, server) }
Options for the modal widget (chakraModal
).
chakraModalOptions( closeOnEsc = TRUE, isCentered = TRUE, motionPreset = "scale", size = "md", ... )
chakraModalOptions( closeOnEsc = TRUE, isCentered = TRUE, motionPreset = "scale", size = "md", ... )
closeOnEsc |
whether to close the modal on pressing the 'esc' key |
isCentered |
whether to center the modal on screen |
motionPreset |
transition that should be used for the modal; one of
|
size |
modal size, |
... |
other attributes of |
A named list, for usage in chakraModal
.
Function to be used as the ui
element of a Shiny app;
it is intended to contain some chakraComponent
elements.
chakraPage(...)
chakraPage(...)
... |
elements to include within the page |
A UI definition that can be passed to the
shinyUI
function.
Create a pin input widget.
chakraPinInput( id, label = NULL, nfields, type = "alphanumeric", size = "md", mask = FALSE, defaultValue = "" )
chakraPinInput( id, label = NULL, nfields, type = "alphanumeric", size = "md", mask = FALSE, defaultValue = "" )
id |
input id |
label |
optional label |
nfields |
number of fields |
type |
either |
size |
one of |
mask |
Boolean, whether to mask the user inputs (like a password input) |
defaultValue |
default value, can be partial |
A widget to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraPinInput( "pininput", label = tags$h2("Enter password"), nfields = 3, mask = TRUE ) ) ) server <- function(input, output, session){ observe({ print(input[["pininput"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraPinInput( "pininput", label = tags$h2("Enter password"), nfields = 3, mask = TRUE ) ) ) server <- function(input, output, session){ observe({ print(input[["pininput"]]) }) } if(interactive()){ shinyApp(ui, server) }
Create a Chakra range slider.
chakraRangeSlider( id, label = NULL, values, min, max, step = NULL, width = NULL, size = "md", colorScheme = "blue", orientation = "horizontal", focusThumbOnChange = TRUE, isDisabled = FALSE, isReadOnly = FALSE, isReversed = FALSE, trackColor = NULL, filledTrackColor = NULL, tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptionsLeft = sliderThumbOptions(), thumbOptionsRight = sliderThumbOptions(), shinyValueOn = "end", ... )
chakraRangeSlider( id, label = NULL, values, min, max, step = NULL, width = NULL, size = "md", colorScheme = "blue", orientation = "horizontal", focusThumbOnChange = TRUE, isDisabled = FALSE, isReadOnly = FALSE, isReversed = FALSE, trackColor = NULL, filledTrackColor = NULL, tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptionsLeft = sliderThumbOptions(), thumbOptionsRight = sliderThumbOptions(), shinyValueOn = "end", ... )
id |
widget id |
label |
label (optional) |
values |
the two initial values |
min |
minimal value |
max |
maximal value |
step |
increment step |
width |
slider width |
size |
size, |
colorScheme |
a Chakra color scheme |
orientation |
slider orientation, |
focusThumbOnChange |
whether to focus the thumb on change |
isDisabled |
whether to disable the slider |
isReadOnly |
read only mode |
isReversed |
whether to reverse the slider |
trackColor |
color of the track |
filledTrackColor |
color of the filled track |
tooltip |
whether to set a tooltip to the thumb |
tooltipOptions |
options of the tooltip, a list created with
|
thumbOptionsLeft |
list of options for the left thumb, created with
|
thumbOptionsRight |
list of options for the right thumb, created with
|
shinyValueOn |
either |
... |
other attributes passed to |
A widget to use in chakraComponent
.
# Run `chakraExample("RangeSlider")` to see a better example. library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraRangeSlider( "slider", label = HTML("<span style='color:red'>Hello range slider!</span>"), values = c(2, 8), min = 0, max = 10, width = "50%", tooltip = TRUE, tooltipOptions = sliderTooltipOptions(placement = "bottom"), shinyValueOn = "end" ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
# Run `chakraExample("RangeSlider")` to see a better example. library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraRangeSlider( "slider", label = HTML("<span style='color:red'>Hello range slider!</span>"), values = c(2, 8), min = 0, max = 10, width = "50%", tooltip = TRUE, tooltipOptions = sliderTooltipOptions(placement = "bottom"), shinyValueOn = "end" ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
Create a Chakra slider.
chakraSlider( id, label = NULL, value, min, max, step = NULL, width = NULL, size = "md", colorScheme = "blue", orientation = "horizontal", focusThumbOnChange = TRUE, isDisabled = FALSE, isReadOnly = FALSE, isReversed = FALSE, trackColor = NULL, filledTrackColor = NULL, mark = FALSE, markOptions = sliderMarkOptions(), tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptions = sliderThumbOptions(), shinyValueOn = "end", ... )
chakraSlider( id, label = NULL, value, min, max, step = NULL, width = NULL, size = "md", colorScheme = "blue", orientation = "horizontal", focusThumbOnChange = TRUE, isDisabled = FALSE, isReadOnly = FALSE, isReversed = FALSE, trackColor = NULL, filledTrackColor = NULL, mark = FALSE, markOptions = sliderMarkOptions(), tooltip = TRUE, tooltipOptions = sliderTooltipOptions(), thumbOptions = sliderThumbOptions(), shinyValueOn = "end", ... )
id |
widget id |
label |
label (optional) |
value |
initial value |
min |
minimal value |
max |
maximal value |
step |
increment step |
width |
slider width |
size |
size, |
colorScheme |
a Chakra color scheme |
orientation |
slider orientation, |
focusThumbOnChange |
whether to focus the thumb on change |
isDisabled |
whether to disable the slider |
isReadOnly |
read only mode |
isReversed |
whether to reverse the slider |
trackColor |
color of the track |
filledTrackColor |
color of the filled track |
mark |
whether to set a mark to the thumb (I personally prefer the tooltip) |
markOptions |
options of the mark, a list created with
|
tooltip |
whether to set a tooltip to the thumb |
tooltipOptions |
options of the tooltip, a list created with
|
thumbOptions |
list of options for the thumb created with
|
shinyValueOn |
either |
... |
other attributes passed to |
A widget to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraSlider( "slider", label = HTML("<span style='color:red'>Hello slider!</span>"), value = 5, min = 0, max = 10, width = "50%", tooltip = TRUE, shinyValueOn = "end" ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", chakraSlider( "slider", label = HTML("<span style='color:red'>Hello slider!</span>"), value = 5, min = 0, max = 10, width = "50%", tooltip = TRUE, shinyValueOn = "end" ) ) ) server <- function(input, output, session){ observe({ print(input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
The 'createStandaloneToast' hook.
createStandaloneToast()
createStandaloneToast()
See Standalone toasts.
A list containing some URL-encoded JavaScript code.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Button( colorScheme = "orange", size = "lg", onClick = jseval(paste( '() => {', ' const toast = getState("toast");', ' toast({', ' position: "bottom",', ' title: "Account created.",', ' description: "We have created your account for you.",', ' status: "success",', ' duration: 3000,', ' isClosable: true', ' });', '}', sep = "\n")), "Show toast" ), states = list(toast = createStandaloneToast()) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Button( colorScheme = "orange", size = "lg", onClick = jseval(paste( '() => {', ' const toast = getState("toast");', ' toast({', ' position: "bottom",', ' title: "Account created.",', ' description: "We have created your account for you.",', ' status: "success",', ' duration: 3000,', ' isClosable: true', ' });', '}', sep = "\n")), "Show toast" ), states = list(toast = createStandaloneToast()) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
Chakra hooks are JavaScript objects; this function allows to
get a property (key) of a hook. See useDisclosure
for an
example.
getHookProperty(hook, property)
getHookProperty(hook, property)
hook |
the name of the hook, usually created in the |
property |
the hook property you want to get |
A list like the return value of jseval
.
Get the value of a React state.
getState(state)
getState(state)
state |
name of the state |
A list like the return value of jseval
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Box( bg = "yellow.100", fontSize = "30px", width = "50%", getState("boxtext") ), br(), Tag$Divider(), br(), Tag$Button( colorScheme = "telegram", size = "lg", onClick = jseval('() => setState("boxtext", "Hello Chakra")'), "Change box text" ) ), states = list(boxtext = "I am the box text") ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Box( bg = "yellow.100", fontSize = "30px", width = "50%", getState("boxtext") ), br(), Tag$Divider(), br(), Tag$Button( colorScheme = "telegram", size = "lg", onClick = jseval('() => setState("boxtext", "Hello Chakra")'), "Change box text" ) ), states = list(boxtext = "I am the box text") ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
List of ionicons.
ionIcons()
ionIcons()
See ionicons website.
The names of the ionicons in a vector.
ionIcons()
ionIcons()
Evaluate JavaScript code in the application.
jseval(code)
jseval(code)
code |
JavaScript code given as a string |
A list containing the URL-encoded JavaScript code.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", Tag$Button( colorScheme = "pink", size = "lg", onClick = jseval('() => alert("Hello Chakra")'), "Trigger alert" ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", Tag$Button( colorScheme = "pink", size = "lg", onClick = jseval('() => alert("Hello Chakra")'), "Trigger alert" ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
Create a JSX element.
jsx(element, preamble = "")
jsx(element, preamble = "")
element |
the JSX element given as a string |
preamble |
JavaScript code to run before, given as a string |
A list containing the URL-encoded strings element
and preamble
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( chakraComponent( "mycomponent", jsx(paste( '<>', ' <Button onClick={onOpen}>Open Modal</Button>', ' <Modal isOpen={isOpen} onClose={onClose}>', ' <ModalOverlay />', ' <ModalContent>', ' <ModalHeader>Modal Title</ModalHeader>', ' <ModalCloseButton />', ' <ModalBody>', ' Sit nulla est ex deserunt exercitation anim occaecat.', ' </ModalBody>', ' <ModalFooter>', ' <Button colorScheme="blue" mr={3} onClick={onClose}>', ' Close', ' </Button>', ' <Button variant="ghost" onClick={setShinyValue}>', ' Secondary Action', ' </Button>', ' </ModalFooter>', ' </ModalContent>', ' </Modal>', '</>', sep = "\n" ), preamble = paste( 'const { isOpen, onOpen, onClose } = useDisclosure();', 'const setShinyValue = () => Shiny.setInputValue("modal", "action");', sep = "\n" ) )) ) server <- function(input, output, session){ observe({ print(input[["modal"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( chakraComponent( "mycomponent", jsx(paste( '<>', ' <Button onClick={onOpen}>Open Modal</Button>', ' <Modal isOpen={isOpen} onClose={onClose}>', ' <ModalOverlay />', ' <ModalContent>', ' <ModalHeader>Modal Title</ModalHeader>', ' <ModalCloseButton />', ' <ModalBody>', ' Sit nulla est ex deserunt exercitation anim occaecat.', ' </ModalBody>', ' <ModalFooter>', ' <Button colorScheme="blue" mr={3} onClick={onClose}>', ' Close', ' </Button>', ' <Button variant="ghost" onClick={setShinyValue}>', ' Secondary Action', ' </Button>', ' </ModalFooter>', ' </ModalContent>', ' </Modal>', '</>', sep = "\n" ), preamble = paste( 'const { isOpen, onOpen, onClose } = useDisclosure();', 'const setShinyValue = () => Shiny.setInputValue("modal", "action");', sep = "\n" ) )) ) server <- function(input, output, session){ observe({ print(input[["modal"]]) }) } if(interactive()){ shinyApp(ui, server) }
Given a JSX string, this function prints the code of the
corresponding React component that can be used in
chakraComponent
.
jsxString2code(jsxString, clipboard = TRUE)
jsxString2code(jsxString, clipboard = TRUE)
jsxString |
JSX code given as a string |
clipboard |
whether to copy the output to the clipboard |
No return value, only prints the code in the console and copy it
to the clipboard if clipboard = TRUE
.
Instead of using this function, rather use the RStudio addin provided by the package. Simply copy some JSX code to your clipboard, and select the 'JSX parser' addin in the RStudio Addins menu.
jsxString <- '<Input type="email" id="myinput" />' jsxString2code(jsxString) jsxString <- '<Button onClick={() => alert("hello")}>Hello</Button>' jsxString2code(jsxString)
jsxString <- '<Input type="email" id="myinput" />' jsxString2code(jsxString) jsxString <- '<Button onClick={() => alert("hello")}>Hello</Button>' jsxString2code(jsxString)
Create a list of options to be passed to the
numericInputOptions
argument in chakraCombinedSlider
.
numberInputOptions( precision = NULL, maxWidth = "80px", fontSize = NULL, fontColor = NULL, borderColor = NULL, focusBorderColor = NULL, borderWidth = NULL, incrementStepperColor = NULL, decrementStepperColor = NULL, ... )
numberInputOptions( precision = NULL, maxWidth = "80px", fontSize = NULL, fontColor = NULL, borderColor = NULL, focusBorderColor = NULL, borderWidth = NULL, incrementStepperColor = NULL, decrementStepperColor = NULL, ... )
precision |
number of decimal points |
maxWidth |
width of the number input, e.g. |
fontSize |
font size of the displayed value, e.g. |
fontColor |
color of the displayed value |
borderColor |
color of the border of the number input |
focusBorderColor |
color of the border of the number input on focus |
borderWidth |
width of the border of the number input,
e.g. |
incrementStepperColor |
color of the increment stepper |
decrementStepperColor |
color of the decrement stepper |
... |
other attributes of |
A list of options to be passed to the
numericInputOptions
argument in chakraCombinedSlider
.
Set a React state from the Shiny server.
setReactState(session, componentId, stateName, value)
setReactState(session, componentId, stateName, value)
session |
Shiny session object |
componentId |
the id of the |
stateName |
the name of the state to be set |
value |
the new value of the state; it can be an R object serializable
to JSON, a React component, a JSX element created with the
|
No return value, called for side effect.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", Tag$Button( id = "button", className = "action-button", colorScheme = "facebook", display = "block", onClick = jseval("(event) => {event.target.disabled = true}"), "Click me to change the content of the container" ), br(), Tag$Divider(), br(), withStates( Tag$Container( maxW = "xl", centerContent = TRUE, bg = "yellow.100", getState("containerContent") ), states = list(containerContent = "I am the container content.") ) ) ) server <- function(input, output, session){ observeEvent(input[["button"]], { setReactState( session = session, componentId = "mycomponent", stateName = "containerContent", value = Tag$Box( padding = "4", maxW = "3xl", fontStyle = "italic", fontWeight = "bold", borderWidth = "2px", "I am the new container content, included in a Box." ) ) }) } if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", Tag$Button( id = "button", className = "action-button", colorScheme = "facebook", display = "block", onClick = jseval("(event) => {event.target.disabled = true}"), "Click me to change the content of the container" ), br(), Tag$Divider(), br(), withStates( Tag$Container( maxW = "xl", centerContent = TRUE, bg = "yellow.100", getState("containerContent") ), states = list(containerContent = "I am the container content.") ) ) ) server <- function(input, output, session){ observeEvent(input[["button"]], { setReactState( session = session, componentId = "mycomponent", stateName = "containerContent", value = Tag$Box( padding = "4", maxW = "3xl", fontStyle = "italic", fontWeight = "bold", borderWidth = "2px", "I am the new container content, included in a Box." ) ) }) } if(interactive()){ shinyApp(ui, server) }
Define the options for the slider mark.
sliderMarkOptions( textAlign = "center", backgroundColor = "blue.500", textColor = "white", margin = "-35px 0 0 -25px", padding = "0 10px", width = "50px", ... )
sliderMarkOptions( textAlign = "center", backgroundColor = "blue.500", textColor = "white", margin = "-35px 0 0 -25px", padding = "0 10px", width = "50px", ... )
textAlign |
text alignment |
backgroundColor |
background color |
textColor |
text color |
margin |
margin (CSS property) |
padding |
padding (CSS property) |
width |
width |
... |
other attributes passed to |
A list of attributes for usage in chakraSlider
.
Define the Chakra slider thumb options.
sliderThumbOptions( width = NULL, height = NULL, color = NULL, borderColor = NULL, borderWidth = NULL, ... )
sliderThumbOptions( width = NULL, height = NULL, color = NULL, borderColor = NULL, borderWidth = NULL, ... )
width |
thumb width |
height |
thumb height |
color |
thumb color |
borderColor |
thumb border color |
borderWidth |
thumb border width |
... |
other attributes passed to |
A list of attributes for usage in chakraSlider
,
chakraCombinedSlider
, or chakraRangeSlider
.
Define the slider tooltip options.
sliderTooltipOptions( hasArrow = TRUE, backgroundColor = "red.600", color = "white", placement = "top", closeOnClick = FALSE, isOpen = TRUE, ... )
sliderTooltipOptions( hasArrow = TRUE, backgroundColor = "red.600", color = "white", placement = "top", closeOnClick = FALSE, isOpen = TRUE, ... )
hasArrow |
whether to include an arrow |
backgroundColor |
background color |
color |
content color |
placement |
tooltip placement; see tooltip placement |
closeOnClick |
whether to close the tooltip on click |
isOpen |
whether the tooltip is open |
... |
other attributes passed to |
A list of attributes for usage in chakraSlider
,
chakraCombinedSlider
, or chakraRangeSlider
.
List of super tiny icons.
superTinyIcons()
superTinyIcons()
See all super tiny icons.
The names of the super tiny icons in a vector.
superTinyIcons()
superTinyIcons()
Create a React component. This is similar to
React
.
Tag
Tag
An object of class ReactTagBuilder
of length 0.
Tag$Box( bg = "tomato", Tag$ButtonGroup( spacing = "4", Tag$Button( "I'm a button" ), Tag$Button( "I'm another button" ) ) )
Tag$Box( bg = "tomato", Tag$ButtonGroup( spacing = "4", Tag$Button( "I'm a button" ), Tag$Button( "I'm another button" ) ) )
The 'useClipboard' hook.
useClipboard(value)
useClipboard(value)
value |
a string |
See useClipboard.
A list containing some URL-encoded JavaScript code.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Box( width = "50%", Tag$Flex( mb = 2, Tag$Input( isReadOnly = TRUE, value = getHookProperty("clipboard", "value") ), Tag$Button( ml = 2, onClick = getHookProperty("clipboard", "onCopy"), jseval('getState("hasCopied") ? "Copied" : "Copy"') ) ), br(), Tag$Divider(), br(), Tag$Editable( bg = "yellow.100", placeholder = "Paste here", Tag$EditablePreview(), Tag$EditableInput() ) ), states = list( clipboard = useClipboard("Hello Chakra"), hasCopied = getHookProperty("clipboard", "hasCopied") ) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Box( width = "50%", Tag$Flex( mb = 2, Tag$Input( isReadOnly = TRUE, value = getHookProperty("clipboard", "value") ), Tag$Button( ml = 2, onClick = getHookProperty("clipboard", "onCopy"), jseval('getState("hasCopied") ? "Copied" : "Copy"') ) ), br(), Tag$Divider(), br(), Tag$Editable( bg = "yellow.100", placeholder = "Paste here", Tag$EditablePreview(), Tag$EditableInput() ) ), states = list( clipboard = useClipboard("Hello Chakra"), hasCopied = getHookProperty("clipboard", "hasCopied") ) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
The 'useDisclosure' hook.
useDisclosure(defaultIsOpen = FALSE)
useDisclosure(defaultIsOpen = FALSE)
defaultIsOpen |
Boolean, the initial value of the |
See useDisclosure.
A list containing some URL-encoded JavaScript code.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Button( colorScheme = "teal", variant = "outline", onClick = getHookProperty("disclosure", "onToggle"), "Click me!" ), Tag$Fade( "in" = getHookProperty("disclosure", "isOpen"), Tag$Box( p = "40px", color = "white", mt = "4", bg = "teal.500", rounded = "md", shadow = "md", "Fade" ) ) ), states = list(disclosure = useDisclosure()) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Button( colorScheme = "teal", variant = "outline", onClick = getHookProperty("disclosure", "onToggle"), "Click me!" ), Tag$Fade( "in" = getHookProperty("disclosure", "isOpen"), Tag$Box( p = "40px", color = "white", mt = "4", bg = "teal.500", rounded = "md", shadow = "md", "Fade" ) ) ), states = list(disclosure = useDisclosure()) ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
The React 'useRef' hook.
useRef(initialValue = NA)
useRef(initialValue = NA)
initialValue |
optional initial value |
A list like the return value of jseval
.
The 'useToast' hook.
useToast()
useToast()
A list containing some URL-encoded JavaScript code.
It does not work well. Use createStandaloneToast
instead.
Create a Chakra component with React states and/or hooks.
withStates(component, states)
withStates(component, states)
component |
a React component |
states |
named list of states; a state value can be an R object
serializable to JSON, a React component ( |
A component to use in chakraComponent
.
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Container( maxW = "xl", centerContent = TRUE, bg = "orange.50", Tag$Heading( getState("heading") ), Tag$Text( "I'm just some text." ) ), br(), Tag$Divider(), br(), Tag$Button( colorScheme = "twitter", display = "block", onClick = jseval( "() => setState('heading', 'I am the new heading.')" ), "Click me to change the heading" ) ), states = list(heading = "I am the heading.") ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }
library(shiny) library(shinyChakraUI) ui <- chakraPage( br(), chakraComponent( "mycomponent", withStates( Tag$Fragment( Tag$Container( maxW = "xl", centerContent = TRUE, bg = "orange.50", Tag$Heading( getState("heading") ), Tag$Text( "I'm just some text." ) ), br(), Tag$Divider(), br(), Tag$Button( colorScheme = "twitter", display = "block", onClick = jseval( "() => setState('heading', 'I am the new heading.')" ), "Click me to change the heading" ) ), states = list(heading = "I am the heading.") ) ) ) server <- function(input, output, session){} if(interactive()){ shinyApp(ui, server) }