README.md

Hotwire for R

R-Universe GitHub R package
version Project Status: Active – The project has reached a stable, usable
state and is being actively
developed. Codecov test
coverage R-CMD-check

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.

Installation

You can install from R Universe:

install.packages("hotwire.R", repos = "https://tjpalanca.r-universe.dev")

Getting Started

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()

Demonstration App

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()

Related work



tjpalanca/hotwire.R documentation built on Dec. 23, 2021, 10:59 a.m.