Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:'jQuery UI' Interactions and Effects for Shiny
Version:0.4.1
Maintainer:Yang Tang <tang_yang@outlook.com>
Description:An extension to shiny that brings interactions and animation effects from 'jQuery UI' library.
License:MIT + file LICENSE
Encoding:UTF-8
Depends:R (≥ 3.2.0)
Imports:shiny (≥ 1.5.0), htmltools, htmlwidgets, jsonlite, rlang
Suggests:ggplot2, highcharter, knitr, markdown, rmarkdown, plotly
URL:https://github.com/yang-tang/shinyjqui,https://yang-tang.github.io/shinyjqui/
BugReports:https://github.com/yang-tang/shinyjqui/issues
RoxygenNote:7.1.2
VignetteBuilder:knitr
NeedsCompilation:no
Packaged:2022-02-03 06:36:22 UTC; tangy53
Author:Yang Tang [aut, cre]
Repository:CRAN
Date/Publication:2022-02-03 07:00:02 UTC

shinyjqui: 'jQuery UI' Interactions and Effects for Shiny

Description

An extension to shiny that brings interactions and animation effects from 'jQuery UI' library.

Author(s)

Maintainer: Yang Tangtang_yang@outlook.com

See Also

Useful links:


Animation effects.

Description

Allow element(s) to show animation effects.

Usage

jqui_effect(ui, effect, options = NULL, duration = 400, complete = NULL)jqui_show(ui, effect, options = NULL, duration = 400, complete = NULL)jqui_hide(ui, effect, options = NULL, duration = 400, complete = NULL)jqui_toggle(ui, effect, options = NULL, duration = 400, complete = NULL)

Arguments

ui

The target ui element(s) to be manipulated. Can be

effect

A string indicating whichanimation effect to use for thetransition.

options

A list of effect-specificproperties andeasing.

duration

A string or number determining how long the animation willrun.

complete

A function to call once the animation is complete, calledonce per matched element.

Details

These functions are R wrappers ofeffect(),hide(),show() andtoggle() from jQuery UI library. Theyshould be used inserver of a shiny document.

Examples

## Not run:   # in shiny ui create a plot  plotOutput('foo')  # in shiny server apply a 'bounce' effect to the plot  jqui_effect('#foo', 'bounce')  # in shiny server hide the plot with a 'fold' effect  jqui_hide('#foo', 'fold')  # in shiny server show the plot with a 'blind' effect  jqui_show('#foo', 'blind')## End(Not run)

Class effects.

Description

Manipulate specified class(es) to matched elements while animating all stylechanges.

Usage

jqui_add_class(  ui,  className,  duration = 400,  easing = "swing",  complete = NULL)jqui_remove_class(  ui,  className,  duration = 400,  easing = "swing",  complete = NULL)jqui_switch_class(  ui,  removeClassName,  addClassName,  duration = 400,  easing = "swing",  complete = NULL)

Arguments

ui

The target ui element(s) to be manipulated. Can be

className

One or more class names (space separated) to be added to orremoved from the class attribute of each matched element.

duration

A string or number determining how long the animation willrun.

easing

A string indicating whicheasing function to use for thetransition.

complete

A js function to call once the animation is complete, calledonce per matched element.

removeClassName

One or more class names (space separated) to beremoved from the class attribute of each matched element.

addClassName

One or more class names (space separated) to be added tothe class attribute of each matched element.

Details

These functions are the R wrappers ofaddClass(),removeClass() andswitchClass() from jQuery UI library.They should be used inserver of a shiny app.

Examples

## Not run:   # in shiny ui create a span  tags$span(id = 'foo', 'class animation demo')  # in shiny server add class 'lead' to the span  jqui_add_class('#foo', className = 'lead')## End(Not run)

Mouse interactions

Description

Attach mouse-based interactions to shiny html tags, shiny input/outputwidgets or static htmlwidgets and provide ways to manipulate them. Theinteractions include:

Usage

jqui_draggable(  ui,  operation = c("enable", "disable", "destroy", "save", "load"),  options = NULL)jqui_droppable(  ui,  operation = c("enable", "disable", "destroy", "save", "load"),  options = NULL)jqui_resizable(  ui,  operation = c("enable", "disable", "destroy", "save", "load"),  options = NULL)jqui_selectable(  ui,  operation = c("enable", "disable", "destroy", "save", "load"),  options = NULL)jqui_sortable(  ui,  operation = c("enable", "disable", "destroy", "save", "load"),  options = NULL)

Arguments

ui

The target ui element(s) to be manipulated. Can be

operation

A string to determine how to manipulate the mouseinteraction. Can be one ofenable,disable,destroy,save andload. Ignored whenui is ashiny.tag orshiny.tag.list object. SeeDetails.

options

A list ofinteraction_specific_options.Ignored whenoperation is set asdestroy. This parameter also accept ashiny option that controls the shiny input value returned from theelement. See Details.

Details

The first parameterui determines the target ui and working mode. If thetarget ui is ashiny.tag (e.g., shiny inputs/outputs or ui created bytags) or ashiny.tag.list (bytagList()) objector a statichtmlwidget, the functions return the a modified ui object withinteraction effects attached. When ajQuery_selector or a javascriptexpression is provided as theui parameter, the functions first use it tolocate the target ui element(s) in the shiny app, and then attach or manipulatethe interactions. Therefore, you can use the first way in theui of a shinyapp to create elements with interaction effects (the ui mode), or use thesecond way in theserver to manipulate the interactions (the server mode).

Theoperation parameter is valid only in server mode. It determines how tomanipulate the interaction, which includes:

With mouse interactions attached, the corresponding interaction states, e.g.position of draggable,size of resizable,selected of selectable andorder of sortable, will be sent to server side in the form of⁠input$<id>_<state>⁠. The default values can be overridden by setting theshiny option in theoptions parameter. Please see the vignette⁠Introduction to shinyjqui⁠ for more details.

Value

The same object passed in theui parameter

Examples

library(shiny)library(highcharter)## used in uijqui_resizable(actionButton('btn', 'Button'))jqui_draggable(plotOutput('plot', width = '400px', height = '400px'),                options = list(axis = 'x'))jqui_selectable(  div(    id = 'sel_plots',    highchartOutput('highchart', width = '300px'),    plotOutput('ggplot', width = '300px')  ),  options = list(    classes = list(`ui-selected` = 'ui-state-highlight')  ))jqui_sortable(tags$ul(  id = 'lst',  tags$li('A'),  tags$li('B'),  tags$li('C')))## used in server## Not run:   jqui_draggable('#foo', options = list(grid = c(80, 80)))  jqui_droppable('.foo', operation = "enable")## End(Not run)## use shiny inputif (interactive()) {  shinyApp(    server = function(input, output) {      output$foo <- renderHighchart({        hchart(mtcars, "scatter", hcaes(x = cyl, y = mpg))      })      output$position <- renderPrint({        print(input$foo_position)      })    },    ui = fluidPage(      verbatimTextOutput('position'),      jqui_draggable(highchartOutput('foo', width = '200px', height = '200px'))    )  )}## custom shiny inputfunc <- JS('function(event, ui){return $(event.target).offset();}')options <-  list(  shiny = list(    abs_position = list(      dragcreate = func, # send returned value back to shiny when interaction is created.      drag = func # send returned value to shiny when dragging.    )  ))jqui_draggable(highchartOutput('foo', width = '200px', height = '200px'),                options = options)

Create a draggable modal dialog UI

Description

This creates the UI for a modal dialog similar toshiny::modalDialog exceptits content is draggable.

Usage

draggableModalDialog(  ...,  title = NULL,  footer = shiny::modalButton("Dismiss"),  size = c("m", "s", "l"),  easyClose = FALSE,  fade = TRUE)

Arguments

...

UI elements for the body of the modal dialog box.

title

An optional title for the dialog.

footer

UI for footer. UseNULL for no footer.

size

One of"s" for small,"m" (the default) for medium,or"l" for large.

easyClose

IfTRUE, the modal dialog can be dismissed byclicking outside the dialog box, or be pressing the Escape key. IfFALSE (the default), the modal dialog can't be dismissed in thoseways; instead it must be dismissed by clicking on amodalButton(), orfrom a call toremoveModal() on the server.

fade

IfFALSE, the modal dialog will have no fade-in animation(it will simply appear rather than fade in to view).

Value

A modified shiny modal dialog UI with its content draggable.


Get available animation effects.

Description

Use this function to get all animation effects in jQuery UI.

Usage

get_jqui_effects()

Value

A character vector of effect names


Enable bookmarking state of mouse interactions

Description

Enable shinybookmarking_stateof mouse interactions. By calling this function inserver, the elements'position,size,⁠selection state⁠ and⁠sorting state⁠ changed by mouseoperations can be saved and restored through an URL.

Usage

jqui_bookmarking()

Create a jQuery UI icon

Description

Create an jQuery UI pre-defined icon. For lists of available icons, seehttps://api.jqueryui.com/theming/icons/.

Usage

jqui_icon(name)

Arguments

name

Class name of icon. The "ui-icon-" prefix can be omitted (i.e.use "ui-icon-flag" or "flag" to display a flag icon)

Value

An icon element

Examples

jqui_icon('caret-1-n')library(shiny)# add an icon to an actionButtonactionButton('button', 'Button', icon = jqui_icon('refresh'))# add an icon to a tabPaneltabPanel('Help', icon = jqui_icon('help'))

Position an element relative to another

Description

Wrapper of the jQuery UI.position()method, allows you to position an element relative to the window, document,another element, or the cursor/mouse, without worrying about offset parents.

Usage

jqui_position(  ui,  my = "center",  at = "center",  of,  collision = "flip",  within = JS("$(window)"))

Arguments

ui

Which element to be positioned. Can be a string ofjQuery_selector or aJS() wrapped javascript expression that returns ajQuery object. Only the firstmatching element will be used.

my

String. Defines which positionon the element being positionedto align with the target element: "horizontal vertical" alignment. A singlevalue such as "right" will be normalized to "right center", "top" will benormalized to "center top" (following CSS convention). Acceptablehorizontal values: "left", "center", "right". Acceptable vertical values:"top", "center", "bottom". Example: "left top" or "center center". Eachdimension can also contain offsets, in pixels or percent, e.g., "right+10top-25%". Percentage offsets are relative to the element being positioned.

at

String. Defines which positionon the target element to alignthe positioned element against: "horizontal vertical" alignment. See themy option for full details on possible values. Percentage offsets arerelative to the target element.

of

Which element to position against. Can be a string ofjQuery_selector or aJS() wrapped javascript expression that returns ajQuery object. Only the firstmatching element will be used.

collision

String. When the positioned element overflows the window insome direction, move it to an alternative position. Similar tomy andat, this accepts a single value or a pair for horizontal/vertical, e.g.,"flip", "fit", "fit flip", "fit none".

  • "flip": Flips the element to the opposite side of the target and thecollision detection is run again to see if it will fit. Whichever sideallows more of the element to be visible will be used.

  • "fit": Shift the element away from the edge of the window.

  • "flipfit": First applies the flip logic, placing the element on whicheverside allows more of the element to be visible. Then the fit logic isapplied to ensure as much of the element is visible as possible.

  • "none": Does not apply any collision detection.

within

Element to position within, affecting collision detection. Canbe a string ofjQuery_selector or aJS() wrapped javascript expression that returns ajQuery object. Only the firstmatching element will be used.


Create a shiny input control to show the order of a set of items

Description

Display a set of items whose order can be changed by drag and drop inside orbetweenorderInput(s). The item order is send back to server in the from ofinput$inputId.

Usage

orderInput(  inputId,  label,  items,  as_source = FALSE,  connect = NULL,  item_class = c("default", "primary", "success", "info", "warning", "danger"),  placeholder = NULL,  width = "500px",  legacy = FALSE,  ...)

Arguments

inputId

Theinput slot that will be used to access the current orderof items.

label

Display label for the control, orNULL for no label.

items

Items to display, can be a list, an atomic vector or a factor.For list or atomic vector, if named, the names are displayed and the orderis given in values. For factor, values are displayed and the order is givenin levels

as_source

A boolean value to determine whether theorderInput is setas source mode. Only works if theconnect argument was set.

connect

Optional. Allow items to be dragged betweenorderInputs.Should be a vector ofinputId(s) of otherorderInput(s) that the itemsfrom thisorderInput should be connected to.

item_class

One of theBootstrap color utility classes to apply toeach item.

placeholder

A character string to show when there is no item left intheorderInput.

width

The width of the input, e.g. '400px', or '100\shiny::validateCssUnit.

legacy

A boolean value. Whether to use the old version of theorderInput function.

...

Arguments passed toshiny::tags$div which is used to build thecontainer of theorderInput.

Details

orderInputs can work in either connected mode or stand-alone mode. Instand-alone mode, items can only be drag and drop inside the input control.In connected mode, items to be dragged betweenorderInputs, which iscontrolled by theconnect parameter. This is a one-way relationship. Toconnect items in both directions, theconnect parameter must be set in bothorderInputs.

When in connected mode,orderInput can be set as source-only through theas_source parameter. The items in a "source"orderInput can only becopied, instead of moved, to other connected non-sourceorderInput(s). Fromshinyjqui v0.4.0, A "source"orderInput will become a "recycle bin" foritems from otherorderInputs as well. This means, if you want to delete anitem, you can drag and drop it into a "source"orderInput. This feature canbe disabled by setting theoptions of non-sourceorderInput(s) aslist(helper = "clone").

From shinyjqui v0.4.0 and above, theorderInput function was implemented inthe similar way as other classical shiny inputs, which brought two changes:

  1. The input value was changed frominput$inputId_order toinput$inputId;

  2. The new version supportsupdateOrderInput function which works in thesame way as other shiny input updater functions. To keep the backwardcompatibility, alegacy argument was provided if user wanted to use the oldversion.

Value

AnorderInput control that can be added to a UI definition.

Examples

orderInput('items1', 'Items1', items = month.abb, item_class = 'info')## build connections between orderInputsorderInput('items2', 'Items2 (can be moved to Items1 and Items4)', items = month.abb,           connect = c('items1', 'items4'), item_class = 'primary')## build connections in source modeorderInput('items3', 'Items3 (can be copied to Items2 and Items4)', items = month.abb,           as_source = TRUE, connect = c('items2', 'items4'), item_class = 'success')## show placeholderorderInput('items4', 'Items4 (can be moved to Items2)', items = NULL, connect = 'items2',           placeholder = 'Drag items here...')

Objects exported from other packages

Description

These objects are imported from other packages. Follow the linksbelow to see their documentation.

htmlwidgets

JS


Create a table output element with selectable rows or cells

Description

Render a standard HTML table with its rows or cells selectable. The serverwill receive the index of selected rows or cells stored in⁠input$<outputId>_selected⁠.

Usage

selectableTableOutput(outputId, selection_mode = c("row", "cell"))

Arguments

outputId

output variable to read the table from

selection_mode

one of"row" or"cell" to define either entire rowor individual cell can be selected.

Details

Use mouse click to select single target, lasso (mouse dragging) to selectmultiple targets, and Ctrl + click to add or remove selection. Inrowselection mode,⁠input$<outputId>_selected⁠ will receive the selected rowindex in the form of numeric vector. Incell selection mode,⁠input$<outputId>_selected⁠ will receive a dataframe withrows andcolumns index of each selected cells.

Value

A table output element that can be included in a panel

See Also

shiny::tableOutput,sortableTableOutput

Examples

## Only run this example in interactive R sessionsif (interactive()) {  shinyApp(    ui = fluidPage(      verbatimTextOutput("selected"),      selectableTableOutput("tbl")    ),    server = function(input, output) {      output$selected <- renderPrint({input$tbl_selected})      output$tbl <- renderTable(mtcars, rownames = TRUE)    }  )}

Create a Checkbox Group Input Control with Sortable Choices

Description

Render a group of checkboxes with multiple choices toggleable. The choicesare also sortable by drag and drop. In addition to the selected values storedin⁠input$<inputId>⁠, the server will also receive the order of choices in⁠input$<inputId>_order⁠.

Usage

sortableCheckboxGroupInput(  inputId,  label,  choices = NULL,  selected = NULL,  inline = FALSE,  width = NULL,  choiceNames = NULL,  choiceValues = NULL)

Arguments

inputId

Theinput slot that will be used to access the value.

label

Display label for the control, orNULL for no label.

choices

List of values to show checkboxes for. If elements of the listare named then that name rather than the value is displayed to the user. Ifthis argument is provided, thenchoiceNames andchoiceValuesmust not be provided, and vice-versa. The values should be strings; othertypes (such as logicals and numbers) will be coerced to strings.

selected

The values that should be initially selected, if any.

inline

IfTRUE, render the choices inline (i.e. horizontally)

width

The width of the input, e.g.'400px', or'100%';seevalidateCssUnit().

choiceNames

List of names and values, respectively,that are displayed to the user in the app and correspond to the eachchoice (for this reason,choiceNames andchoiceValuesmust have the same length). If either of these arguments isprovided, then the othermust be provided andchoicesmust not be provided. The advantage of using both of these overa named list forchoices is thatchoiceNames allows anytype of UI object to be passed through (tag objects, icons, HTML code,...), instead of just simple text. See Examples.

choiceValues

List of names and values, respectively,that are displayed to the user in the app and correspond to the eachchoice (for this reason,choiceNames andchoiceValuesmust have the same length). If either of these arguments isprovided, then the othermust be provided andchoicesmust not be provided. The advantage of using both of these overa named list forchoices is thatchoiceNames allows anytype of UI object to be passed through (tag objects, icons, HTML code,...), instead of just simple text. See Examples.

Value

A list of HTML elements that can be added to a UI definition

See Also

shiny::checkboxGroupInput,sortableRadioButtons(),sortableTableOutput(),sortableTabsetPanel()

Examples

## Only run this example in interactive R sessionsif (interactive()) {  shinyApp(    ui = fluidPage(      sortableCheckboxGroupInput("foo", "SortableCheckboxGroupInput",                                 choices = month.abb),      verbatimTextOutput("order")    ),    server = function(input, output) {      output$order <- renderPrint({input$foo_order})    }  )}

Create radio buttons with sortable choices

Description

Create a set of radio buttons used to select an item from a list. The choicesare sortable by drag and drop. In addition to the selected values stored in⁠input$<inputId>⁠, the server will also receive the order of choices in⁠input$<inputId>_order⁠.

Usage

sortableRadioButtons(  inputId,  label,  choices = NULL,  selected = NULL,  inline = FALSE,  width = NULL,  choiceNames = NULL,  choiceValues = NULL)

Arguments

inputId

Theinput slot that will be used to access the value.

label

Display label for the control, orNULL for no label.

choices

List of values to select from (if elements of the list arenamed then that name rather than the value is displayed to the user). Ifthis argument is provided, thenchoiceNames andchoiceValues must notbe provided, and vice-versa. The values should be strings; other types(such as logicals and numbers) will be coerced to strings.

selected

The initially selected value. If not specified, then itdefaults to the first item inchoices. To start with no items selected,usecharacter(0).

inline

IfTRUE, render the choices inline (i.e. horizontally)

width

The width of the input, e.g.'400px', or'100%';seevalidateCssUnit().

choiceNames

List of names and values, respectively, thatare displayed to the user in the app and correspond to the each choice (forthis reason,choiceNames andchoiceValues must have the same length).If either of these arguments is provided, then the othermust be providedandchoicesmust not be provided. The advantage of using both of theseover a named list forchoices is thatchoiceNames allows any type of UIobject to be passed through (tag objects, icons, HTML code, ...), insteadof just simple text. See Examples.

choiceValues

List of names and values, respectively, thatare displayed to the user in the app and correspond to the each choice (forthis reason,choiceNames andchoiceValues must have the same length).If either of these arguments is provided, then the othermust be providedandchoicesmust not be provided. The advantage of using both of theseover a named list forchoices is thatchoiceNames allows any type of UIobject to be passed through (tag objects, icons, HTML code, ...), insteadof just simple text. See Examples.

Value

A set of radio buttons that can be added to a UI definition.

See Also

shiny::radioButtons,sortableCheckboxGroupInput,sortableTableOutput,sortableTabsetPanel

Examples

## Only run this example in interactive R sessionsif (interactive()) {  shinyApp(    ui = fluidPage(      sortableRadioButtons("foo", "SortableRadioButtons",                                 choices = month.abb),      verbatimTextOutput("order")    ),    server = function(input, output) {      output$order <- renderPrint({input$foo_order})    }  )}

Create a table output element with sortable rows

Description

Render a standard HTML table with table rows sortable by drag and drop. Theorder of table rows is recorded in⁠input$<outputId>_order⁠.

Usage

sortableTableOutput(outputId)

Arguments

outputId

output variable to read the table from

Value

A table output element that can be included in a panel

See Also

shiny::tableOutput,sortableRadioButtons,sortableCheckboxGroupInput,sortableTabsetPanel,selectableTableOutput

Examples

## Only run this example in interactive R sessionsif (interactive()) {  shinyApp(    ui = fluidPage(      verbatimTextOutput("rows"),      sortableTableOutput("tbl")    ),    server = function(input, output) {      output$rows <- renderPrint({input$tbl_row_index})      output$tbl <- renderTable(mtcars, rownames = TRUE)    }  )}

Create a tabset panel with sortable tabs

Description

Create a tabset that containsshiny::tabPanel elements. The tabs aresortable by drag and drop. In addition to the activated tab title stored in⁠input$<id>⁠, the server will also receive the order of tabs in⁠input$<id>_order⁠.

Usage

sortableTabsetPanel(  ...,  id = NULL,  selected = NULL,  type = c("tabs", "pills", "hidden"),  header = NULL,  footer = NULL)

Arguments

...

tabPanel() elements to include in the tabset

id

If provided, you can use⁠input$⁠id in yourserver logic to determine which of the current tabs is active. The valuewill correspond to thevalue argument that is passed totabPanel().

selected

Thevalue (or, if none was supplied, thetitle)of the tab that should be selected by default. IfNULL, the firsttab will be selected.

type
"tabs"

Standard tab look

"pills"

Selected tabs use the background fill color

"hidden"

Hides the selectable tabs. Usetype = "hidden" inconjunction withtabPanelBody() andupdateTabsetPanel() to control theactive tab via other input controls. (See example below)

header

Tag or list of tags to display as a common header above alltabPanels.

footer

Tag or list of tags to display as a common footer below alltabPanels

Value

A tabset that can be passed toshiny::mainPanel

See Also

shiny::tabsetPanel,sortableRadioButtons,sortableCheckboxGroupInput,sortableTableOutput

Examples

## Only run this example in interactive R sessionsif (interactive()) {  shinyApp(    ui = fluidPage(      sortableTabsetPanel(        id = "tabs",        tabPanel(title = "A", "AAA"),        tabPanel(title = "B", "BBB"),        tabPanel(title = "C", "CCC")      ),      verbatimTextOutput("order")    ),    server = function(input, output) {      output$order <- renderPrint({input$tabs_order})    }  )}

Change the value of an orderInput on the client

Description

Similar to the input updater functions of shiny package, this function send amessage to the client, telling it to change the settings of anorderInputobject. Any arguments with NULL values will be ignored; they will not resultin any changes to the input object on the client. The function can't updatethe "source"orderInputs.

Usage

updateOrderInput(  session,  inputId,  label = NULL,  items = NULL,  connect = NULL,  item_class = NULL)

Arguments

session

Thesession object passed to function given toshinyServer.

inputId

Theinput slot that will be used to access the current orderof items.

label

Display label for the control, orNULL for no label.

items

Items to display, can be a list, an atomic vector or a factor.For list or atomic vector, if named, the names are displayed and the orderis given in values. For factor, values are displayed and the order is givenin levels

connect

Optional. Allow items to be dragged betweenorderInputs.Should be a vector ofinputId(s) of otherorderInput(s) that the itemsfrom thisorderInput should be connected to.

item_class

One of theBootstrap color utility classes to apply toeach item.

Examples

library(shiny)if (interactive()) {  ui <- fluidPage(    orderInput("foo", "foo",               items = month.abb[1:3],               item_class = 'info'),    verbatimTextOutput("order"),    actionButton("update", "update")  )  server <- function(input, output, session) {    output$order <- renderPrint({input$foo})    observeEvent(input$update, {      updateOrderInput(session, "foo",                       items = month.abb[1:6],                       item_class = "success")    })  }  shinyApp(ui, server)}

[8]ページ先頭

©2009-2025 Movatter.jp