blockr.session adds project (i.e. board) persistence to blockr apps: save, restore and manage boards from within a running app. It provides a manage_project() plugin backed by the pins package – a more capable alternative to blockr.core’s built-in preserve_board(), which offers only simple file upload and download.
Installation
You can install the development version of blockr.session from GitHub with:
# install.packages("pak")
pak::pak("BristolMyersSquibb/blockr.session")Example
We can start up an app that uses the manage_project() plugin by swapping out the default preserve_board() plugin.
library(blockr.core)
library(blockr.dock)
library(blockr.session)
serve(
new_dock_board(),
plugins = custom_plugins(manage_project())
)The default storage backend is user_pins_board(): on Posit Connect it resolves per-visitor pin storage from the visitor’s own session token (falling back to the application’s Connect credentials), and off Connect it falls back to pins::board_local(). Override it by setting the session_mgmt_backend blockr.core::blockr_option().
Custom storage backends
Storage is a pluggable S3 contract, not tied to pins. user_pins_board() is the default backend, but you can implement your own (a database, an object store, a REST service) by defining methods for the exported rack generics. See vignette("custom-storage-backend") for a worked, file-based example.
Connect storage
On Posit Connect with the Connect API Integration enabled, each user reads and writes pins under their own account out of the box, with no backend option to set. The navbar dropdown gains a Sharing tab (next to Workflows and History) that lets you set visibility and share with other Connect users.
To override the default, set the option to a pins board or to a function returning one, which blockr.session resolves once per session so credentials are picked up at runtime. For example, to use a single shared namespace on the publisher’s account instead of per-visitor storage:
options(blockr.session_mgmt_backend = pins::board_connect)Deploying to Posit Connect
When deploying to Connect no backend option is needed: the default user_pins_board() picks up Connect credentials from the environment automatically.
Per-user pins with the Connect API Integration
Without the integration, every viewer’s pins are stored under the application’s own Connect account, a single shared namespace. To have each viewer’s pins saved under their own account instead, enable the Connect API Integration for the content:
- In Connect, open the content’s Settings → Access tab.
- Under API Integrations, enable the Posit Connect integration.
- Set the maximum role to Viewer (sufficient for reading and writing pins).
With the integration enabled, Connect attaches a per-visitor session token to each request, which user_pins_board() exchanges (via connectapi::connect()) for a viewer-scoped API key, so the connectapi package is required for this path.