KinoPhoenixLiveView allows you to embed Phoenix LiveView applications within Livebook as interactive Kino widgets. It abstracts away the complexity of setting up a full Phoenix endpoint by providing a simple interface with pre-configured option sets.
Install using mix.install/1.
mix.install([
{:kino_phoenix_liveview, "~> 0.1.0"}
])The primary interface is the KinoPhoenixLiveView.new/1 function. This function starts a proxy endpoint that serves your LiveView inside an iframe, then returns a Kino widget that you can render in Livebook. Every call must include a :path option. You can also override the default LiveView, layout, router, or endpoint if needed.
Uses default modules for LiveView, layout, router, and endpoint.
KinoPhoenixLiveView.new(path: "/proxy/apps/my_app")Override the default LiveView module.
KinoPhoenixLiveView.new(path: "/proxy/apps/my_app", live_view: MyApp.LiveView)Customize both the LiveView module and the layout.
KinoPhoenixLiveView.new(
path: "/proxy/apps/my_app",
live_view: MyApp.LiveView,
root_layout: MyApp.Layout
)Provide your own router for request dispatching.
KinoPhoenixLiveView.new(path: "/proxy/apps/my_app", router: MyApp.Router)Use a custom Phoenix endpoint.
KinoPhoenixLiveView.new(path: "/proxy/apps/my_app", endpoint: MyApp.Endpoint)If not overridden, the following defaults are used: • LiveView: KinoPhoenixLiveView.RootLive • Layout: KinoPhoenixLiveView.Layout • Router: KinoPhoenixLiveView.ProxyRouter • Endpoint: KinoPhoenixLiveView.ProxyEndpoint
KinoPhoenixLiveView simplifies embedding LiveView in Livebook by:
- Configuration: Validating and merging your options with sensible defaults.
- Environment Setup: Configuring the necessary application environment for your LiveView.
- Process Supervision: Starting a minimal supervision tree to support the LiveView proxy.
- Proxy Endpoint: Launching a proxy endpoint that serves your LiveView via an iframe.
- Iframe Widget: Returning a Kino widget that displays your LiveView inside Livebook.
Below is a minimal example of how to use KinoPhoenixLiveView in a Livebook notebook:
# Install the dependency (run this cell first)
mix.install([
{:kino_phoenix_liveview, "~> 0.1.2"}
])
# Launch the LiveView in an iframe using the default settings.
KinoPhoenixLiveView.new(path: "/proxy/apps/my_app")Contributions are welcome! Please open an issue or submit a pull request if you have ideas, bug fixes, or improvements.
This project is licensed under the MIT License.