Open
Conversation
This was referenced Jan 14, 2026
Implements a base custom element class `ShinyReactComponentElement` that handles the React lifecycle, parsing config from attributes, wrapping the component in an ID namespace, and allowing the component to accept Shiny UI/inputs/outputs seamlessly as children with named slots. In most cases, this makes it super simple to create a new Shiny-React component by just extending this base class and specifying the React component to render.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2
The core idea is to bring the concept of Shiny modules to shiny-react with a
ShinyModuleProviderthat lets you namespace the client-side IDs to match Shiny's server-side modules patterns.These instructions (to be added to the
shiny/shiny-reactskill) showcase the approach nicely:Because shiny-react components have different lifecycle needs, I wrapped up all of the boilerplate you'd end up needing to implement in a custom web element into a base
ShinyReactComponentElementcustom element that in the most simple case you just need to extend and tell it which component it wraps:That's it! The base class automatically:
ShinyModuleProviderif the element has anidattributedata-*attributes into props viagetConfig()(with JSON auto-parsing)For elements that need to wrap Shiny UI/inputs/output,
ShinyReactComponentElementgrabs it's children and makes them available to the be used in the React component. Groups of elements can be re-routed using thedata-slotattribute which gives each slot a name.In your React component, call
onSlotMount(slotName, containerElement)after the container mounts to move Shiny content into place.Slot naming:
data-slot="name"attributes in R/Python to create named slotsdata-slotelements exist, all children are captured as__children__