knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Hotwire is an alternative approach to building modern web applications without using much JavaScript by sending HTML instead of JSON over the wire. This package enables R developers to develop web applications that use the Hotwire frameworks.
You can install from R Universe:
install.packages("hotwire.R", repos = "https://tjpalanca.r-universe.dev")
Creating a {webtools}
App with Hotwire plugins is quite simple:
# Load the package library(webtools) library(hotwire.R) # Initialize application with Hotwire plugins app <- App$new( # Hotwire cannot work without HTML dependency HTMLPlugin$new(), # Turbo Dependency Turbo$new( turbo_socket = TRUE, app_version = "1.0.0" ), # Stimulus Dependency Stimulus$new( app_version = "1.0.0", controllers = list() ), # Overall Hotwire Hotwire$new() ) # Add a route for the homepage app$hotwire$router("/", function(request, response, keys, ...) { response$body <- html_tags( h1("Hello World!"), h2("This is powered by Hotwire Turbo and Stimulus") ) }) # Start the application app$lifecycle_start()
The functionality of Hotwire is best demonstrated by the demo application.
Run it by using hotwire_demo()
application.
# Load the package library(hotwire.R) # Create and run the demo app app <- hotwire_demo() app$lifecycle_start()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.