| Title: | Layout Manager Widget for R and 'shiny' Apps |
|---|---|
| Description: | Provides R bindings to the 'dockview' 'JavaScript' library <https://dockview.dev/>. Create fully customizable grid layouts (docks) in seconds to include in interactive R reports with R Markdown or 'Quarto' or in 'shiny' apps <https://shiny.posit.co/>. In 'shiny' mode, modify docks by dynamically adding, removing or moving panels or groups of panels from the server function. Choose among 18 stunning themes (dark and light), serialise the state of a dock to restore it later. |
| Authors: | David Granjon [aut, cre], Nelson Stevens [aut], Nicolas Bennett [aut], mathuo [cph], cynkra GmbH [fnd] |
| Maintainer: | David Granjon <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0.9001 |
| Built: | 2026-10-12 23:11:41 UTC |
| Source: | https://github.com/cynkra/dockViewR |
Manipulate edge groups, that is groups pinned to one of the four edges of a dock, from the server. See https://dockview.dev/docs/core/groups/edgeGroups.
add_edge_group(dock, edge_group) remove_edge_group(dock, position) set_edge_group_collapsed(dock, position, collapsed) set_edge_group_visible(dock, position, visible) set_edge_group_size(dock, position, size)add_edge_group(dock, edge_group) remove_edge_group(dock, position) set_edge_group_collapsed(dock, position, collapsed) set_edge_group_visible(dock, position, visible) set_edge_group_size(dock, position, size)
dock |
Dock proxy object created with |
edge_group |
An edge group object created with |
position |
Edge position. One of |
collapsed |
Whether the edge group should be collapsed. |
visible |
Whether the edge group should be visible. |
size |
Target size of the edge group, as a fraction between 0 and 1 of the dock's width (left and right rails) or height (top and bottom ones). |
add_edge_group(): pins a new edge group to the requested edge.
remove_edge_group(): removes the edge group pinned to position,
disposing of the panels it holds.
set_edge_group_visible(): shows or hides the edge group at position
without removing it. An invisible rail renders at zero and keeps whatever
collapsed state it had.
set_edge_group_collapsed(): collapses the edge group at position to its
collapsed_size, or expands it again. A collapsed rail keeps its header
strip standing, which is what distinguishes it from an invisible one. This
is the server-side equivalent of the user gesture, a click on the rail's
active tab.
It is the only route to the collapsed state of a dock that is already
running. The state can also be declared two other ways, neither of which
needs this: edge_group(collapsed = TRUE) at construction, and the
edgeGroups entry of a payload handed to restore_dock(), which carries
collapsed beside size and visible and is honoured on restore.
set_edge_group_size(): resizes the edge group at position along its
own axis, to size of the dock: of its width for a "left" or "right"
rail, of its height for a "top" or "bottom" one. A fraction rather than
pixels, as for set_size(), since the server does not know how large the
dock is. It is converted to pixels when the call lands, and the rail then
holds that width as the dock resizes, as rails do. dockview clamps it to
the rail's minimum_size / maximum_size and to the space available. On a
collapsed rail the size is the one it expands to.
Read either state back with is_edge_group_visible() and
is_edge_group_collapsed(), and the size, in pixels, from
get_edge_groups().
All functions return the dock proxy object invisibly, so they can be chained.
edge_group(), is_edge_group_visible(),
is_edge_group_collapsed()
Functions to dynamically manipulate panels in a dockview instance.
add_panel(dock, panel, ...) remove_panel(dock, id) set_panel_title(dock, id, title) select_panel(dock, id) move_panel(dock, id, position) move_group(dock, from, to, position = NULL) move_group2(dock, from, to, position = NULL) set_size(dock, id, size)add_panel(dock, panel, ...) remove_panel(dock, id) set_panel_title(dock, id, title) select_panel(dock, id) move_panel(dock, id, position) move_group(dock, from, to, position = NULL) move_group2(dock, from, to, position = NULL) set_size(dock, id, size)
dock |
Dock proxy object created with |
panel |
A panel object (for |
... |
Additional options (currently unused). |
id |
Panel ID (character string). |
title |
New panel title. |
position |
For |
from |
Source group/panel ID (for move operations). |
to |
Destination group/panel ID (for move operations). |
size |
Target size for a group along its splitview axis, as a fraction
between 0 and 1 of that splitview (for |
set_panel_title(): Sets the title of a panel dynamically.
add_panel(): Adds a new panel to the dockview
remove_panel(): Removes an existing panel
select_panel(): Selects/focuses a specific panel
move_panel(): Moves an existing panel next to a reference panel or group,
using the same position vocabulary as panel()
move_group(): Moves a group using group IDs
move_group2(): Moves a group using panel IDs
set_size(): Resizes the group a panel belongs to, as a fraction of its
splitview; the other groups in the split keep their relative sizes
All functions return the dock proxy object invisibly, allowing for method chaining.
An example of a JavaScript function that can be used as a default when adding a new tab/panel.
default_add_tab_callback()default_add_tab_callback()
An add tab callback runs when the "+" button in a group's header is clicked,
and is called with three arguments: the group's header config, the click
event and the button itself. The config carries the dock's id in
config.dockId and the group's in config.group.id. To place something at
the button, such as a menu, use the button's box,
button.getBoundingClientRect(). The button stays available to a callback
that defers its work, whereas the browser resets event.currentTarget to
null once the event has been handled, and the click point,
event.clientX and event.clientY, is 0, 0 when the click does not come
from a pointer, as for element.click() and some assistive technology. The
default callback uses neither and sets input[["<dock_ID>_panel-to-add"]]
to the group's id.
An object of class JS_EVAL representing the JavaScript callback.
new_add_tab_plugin( enable = TRUE, callback = htmlwidgets::JS( "(config, event, button) => { const box = button.getBoundingClientRect(); Shiny.setInputValue( `${config.dockId}_add-tab`, { group: config.group.id, left: box.left, bottom: box.bottom }, { priority: 'event' } ); }" ) )new_add_tab_plugin( enable = TRUE, callback = htmlwidgets::JS( "(config, event, button) => { const box = button.getBoundingClientRect(); Shiny.setInputValue( `${config.dockId}_add-tab`, { group: config.group.id, left: box.left, bottom: box.bottom }, { priority: 'event' } ); }" ) )
An example of a JavaScript function that can be used as a default when removing a tab/panel.
default_remove_tab_callback()default_remove_tab_callback()
An object of class JS_EVAL representing the JavaScript callback.
Creates an interactive dock view widget that enables flexible layout management with draggable, resizable, and dockable panels. This is a wrapper around the dockview.dev JavaScript library, providing a powerful interface for creating IDE-like layouts in Shiny applications or R Markdown documents.
dock_view( panels = list(), ..., theme = c("light-spaced", "light", "abyss", "abyss-spaced", "dark", "vs", "dracula", "nord", "nord-spaced", "catppuccin-mocha", "catppuccin-mocha-spaced", "monokai", "solarized-light", "solarized-light-spaced", "github-dark", "github-dark-spaced", "github-light", "github-light-spaced"), edge_groups = list(), add_tab = new_add_tab_plugin(), close_icon = NULL, width = NULL, height = NULL, elementId = NULL )dock_view( panels = list(), ..., theme = c("light-spaced", "light", "abyss", "abyss-spaced", "dark", "vs", "dracula", "nord", "nord-spaced", "catppuccin-mocha", "catppuccin-mocha-spaced", "monokai", "solarized-light", "solarized-light-spaced", "github-dark", "github-dark-spaced", "github-light", "github-light-spaced"), edge_groups = list(), add_tab = new_add_tab_plugin(), close_icon = NULL, width = NULL, height = NULL, elementId = NULL )
panels |
An unnamed list of |
... |
Other options. See https://dockview.dev/docs/api/dockview/options/. |
theme |
Theme. One of
|
edge_groups |
Optional unnamed list of |
add_tab |
Globally controls the add tab behavior. List with enable and callback.
Enable is a boolean, default to FALSE and callback is a
JavaScript function passed with JS.
See |
close_icon |
Icon of the close button on each tab in "manual" remove
mode (see |
width |
Widget width. |
height |
Widget height. |
elementId |
When used outside Shiny. |
An HTML widget object.
Create plugins to enable additional functionality in dock view interfaces. Currently supports "add_tab" and "remove_tab" plugins.
new_dock_view_plugin(type, ...) ## S3 method for class 'add_tab' new_dock_view_plugin(type, enable = FALSE, callback = NULL, ...) ## S3 method for class 'remove_tab' new_dock_view_plugin(type, enable = FALSE, callback = NULL, mode = "auto", ...) new_add_tab_plugin(enable = FALSE, callback = NULL, ...) new_remove_tab_plugin(enable = FALSE, callback = NULL, mode = "auto", ...)new_dock_view_plugin(type, ...) ## S3 method for class 'add_tab' new_dock_view_plugin(type, enable = FALSE, callback = NULL, ...) ## S3 method for class 'remove_tab' new_dock_view_plugin(type, enable = FALSE, callback = NULL, mode = "auto", ...) new_add_tab_plugin(enable = FALSE, callback = NULL, ...) new_remove_tab_plugin(enable = FALSE, callback = NULL, mode = "auto", ...)
type |
Character string specifying the plugin type. |
... |
Additional plugin configuration arguments. |
enable |
Logical, whether the plugin functionality is enabled. |
callback |
Optional JavaScript function. If |
mode |
For remove_tab plugins only. One of "auto" or "manual". |
A dock view plugin object of class add_tab or remove_tab, depending
on the choosen 'type“.
# Add tab plugin new_dock_view_plugin("add_tab", enable = TRUE) new_add_tab_plugin(enable = TRUE) # convenience function # Remove tab plugin new_dock_view_plugin("remove_tab", enable = TRUE, mode = "auto") new_remove_tab_plugin(enable = TRUE, mode = "manual") # convenience function# Add tab plugin new_dock_view_plugin("add_tab", enable = TRUE) new_add_tab_plugin(enable = TRUE) # convenience function # Remove tab plugin new_dock_view_plugin("remove_tab", enable = TRUE, mode = "auto") new_remove_tab_plugin(enable = TRUE, mode = "manual") # convenience function
This function creates a proxy object that can be used to update an existing dockview instance after it has been rendered in the UI. The proxy allows for server-side modifications of the graph without completely re-rendering it.
dock_view_proxy(id, data = NULL, session = getDefaultReactiveDomain())dock_view_proxy(id, data = NULL, session = getDefaultReactiveDomain())
id |
Character string matching the ID of the dockview instance to be modified. |
data |
Unused parameter (for future compatibility). |
session |
The Shiny session object within which the graph exists. By default, this uses the current reactive domain. |
A proxy object of class "dock_view_proxy" that can be used with dockview proxy methods
such as add_panel(), remove_panel(), etc. It contains:
id: The ID of the dockview instance.
session: The Shiny session object.
Output and render functions for using dock_view within Shiny applications and interactive Rmd documents.
dockViewOutput(outputId, width = "100%", height = "400px") dock_view_output(outputId, width = "100%", height = "400px") renderDockView(expr, env = parent.frame(), quoted = FALSE) render_dock_view(expr, env = parent.frame(), quoted = FALSE)dockViewOutput(outputId, width = "100%", height = "400px") dock_view_output(outputId, width = "100%", height = "400px") renderDockView(expr, env = parent.frame(), quoted = FALSE) render_dock_view(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width, height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a dock_view |
env |
The environment in which to evaluate |
quoted |
Is |
dockViewOutput and dock_view_output
return a Shiny output function that can be used in the UI definition.
renderDockView and render_dock_view return a
Shiny render function that can be used in the server definition to
render a dock_view element.
Create an edge group, that is a group
pinned to one of the four edges (left, right, top, bottom) of a
dock_view(). Edge groups support tabs, drag-and-drop, overflow and the
full group panel API. They cannot be maximised, floated or popped out.
edge_group( id, position = c("left", "right", "top", "bottom"), initial_size = NULL, minimum_size = NULL, maximum_size = NULL, collapsed = FALSE, collapsed_size = NULL, ... )edge_group( id, position = c("left", "right", "top", "bottom"), initial_size = NULL, minimum_size = NULL, maximum_size = NULL, collapsed = FALSE, collapsed_size = NULL, ... )
id |
Edge group unique id. Used to reference the group from a
|
position |
Edge on which to pin the group. One of |
initial_size |
Initial size of the edge group, in pixels. |
minimum_size |
Minimum size of the edge group, in pixels. |
maximum_size |
Maximum size of the edge group, in pixels. |
collapsed |
Whether the edge group is initially collapsed. |
collapsed_size |
Size of the edge group when collapsed, in pixels.
Defaults to |
... |
Other options forwarded to Two of those options need a dockview module that this package does not
bundle, and have no effect here: Everything else about an edge group is core, including collapsing. Clicking
the active tab of a rail collapses it to |
Pass edge groups to dock_view() through edge_groups, or add them on
the fly from the server with add_edge_group().
An edge group's size, visibility, collapsed state and panel contents are part
of the serialised layout, so save_dock() and restore_dock() round-trip a
rail along with the rest of the dock.
A list of class dock_edge_group with the camelCased options
ready to be sent to the dockview JavaScript API. Contains at least:
id: the edge group id (string).
position: one of "left", "right", "top", "bottom".
options: a list of options forwarded to api.addEdgeGroup().
add_edge_group(), remove_edge_group(),
set_edge_group_visible(), set_edge_group_size().
Edge groups are serialised beside the grid rather than inside it, keyed by
edge rather than by group id. get_edge_groups() returns that raw record;
the group-level helpers (get_groups_ids(), get_groups_panels(),
get_active_views()) fold edge groups in so a rail's panels are reported
like any other group's.
Collapsed and invisible are different states: a collapsed rail keeps its
header strip standing, while an invisible one renders at zero and keeps
whatever collapsed state it had. Set it with set_edge_group_collapsed().
get_dock(dock) get_panels(dock) get_panels_ids(dock) get_active_group(dock) get_grid(dock) get_edge_groups(dock) is_edge_group_visible(dock, position) is_edge_group_collapsed(dock, position) grid_shape(dock) get_groups(dock) get_groups_ids(dock) get_groups_panels(dock) get_active_views(dock) get_active_panel(dock) save_dock(dock) restore_dock(dock, data)get_dock(dock) get_panels(dock) get_panels_ids(dock) get_active_group(dock) get_grid(dock) get_edge_groups(dock) is_edge_group_visible(dock, position) is_edge_group_collapsed(dock, position) grid_shape(dock) get_groups(dock) get_groups_ids(dock) get_groups_panels(dock) get_active_views(dock) get_active_panel(dock) save_dock(dock) restore_dock(dock, data)
dock |
Dock proxy created with |
position |
Edge position. One of |
data |
Data representing a serialised dock object. |
get_dock returns a list of 3 elements:
grid: a list representing the dock layout.
panels: a list having the same structure as panel() composing the dock.
activeGroup: the current active group (a string).
Each other function allows to deep dive into the returned
value of get_dock().
get_panels() returns the panels element of get_dock().
get_panels_ids() returns a character vector containing all panel ids
from get_panels().
get_active_group() extracts the activeGroup component of
get_dock() as a string.
get_active_views() is a convenience function that returns the active view
in each group.
get_active_panel() is a convenience function that returns the active panel
in the active group.
get_grid() returns the grid element of get_dock() which is a list.
grid_shape() returns the structural shape of get_grid(): the
branch / leaf nesting, orientation, group ids, panel membership and order,
with all absolute geometry (size, width, height) dropped. Pixel
geometry is volatile – and in a headless render not even a valid partition –
so snapshotting structure alone keeps the layout coverage that matters
without the flake.
get_groups() returns a list of panel groups from get_grid().
get_groups_ids() returns a character vector of groups ids
from get_groups().
get_groups_panels() returns a list of character vector containing
the ids of each panel within each group.
save_dock() and restore_dock() are used for their side effect to
allow to respectively serialise and restore a dock object.
TRUE or FALSE, or NULL when no edge group is pinned to
position (or the dock has not yet published a state).
TRUE or FALSE, or NULL when no edge group is pinned to
position (or the dock has not yet published a state).
Only works with server side functions like add_panel. Don't call it from the UI.
Check if object is an add tab plugin
is_add_tab_plugin(x)is_add_tab_plugin(x)
x |
An object to test. |
Logical value.
Check if object is a dock view plugin of specific type
is_dock_view_plugin(x, type)is_dock_view_plugin(x, type)
x |
An object to test. |
type |
Character string specifying plugin type ("add_tab" or "remove_tab"). |
Logical value indicating whether the object is the specified plugin type.
Check whether an object is an edge group
is_edge_group(x)is_edge_group(x)
x |
An object to test. |
Logical value indicating whether x was created with edge_group().
Check if object is a remove tab plugin
is_remove_tab_plugin(x)is_remove_tab_plugin(x)
x |
An object to test. |
Logical value.
Create a panel for use within a dock_view() widget.
Panels are the main container components that can be docked, dragged,
resized, and arranged within the dockview interface.
panel( id, title, content, active = TRUE, remove = new_remove_tab_plugin(), style = list(padding = "10px", overflow = "auto", height = "100%", margin = "10px"), ... )panel( id, title, content, active = TRUE, remove = new_remove_tab_plugin(), style = list(padding = "10px", overflow = "auto", height = "100%", margin = "10px"), ... )
id |
Panel unique id. |
title |
Panel title. |
content |
Panel content. Can be a list of Shiny tags. |
active |
Is active? |
remove |
List with two fields: enable and mode. Enable is a boolean
and mode is one of |
style |
List of CSS style attributes to apply to the panel content. See defaults |
... |
Other options passed to the API. See https://dockview.dev/docs/api/dockview/panelApi/. If you pass position, it must be a list with 2 fields:
|
A list representing a panel object to be consumed by dock_view:
id: unique panel id (string).
title: panel title (string).
content: panel content (shiny.tag.list or single shiny.tag).
active: whether the panel is active or not (boolean).
...: extra parameters to pass to the API.
This does not rerender the widget, just update options like global theme.
update_dock_view(dock, options)update_dock_view(dock, options)
dock |
Dock proxy created with |
options |
List of options for the dock_view instance. |
This function is called for its side effect. It sends a message to JavaScript through the current websocket connection, leveraging the shiny session object.