Skip to content

Instantly share code, notes, and snippets.

@kylebutts
Created March 13, 2024 21:10
Show Gist options
  • Save kylebutts/0511de9eb935b65cdc752454322c186b to your computer and use it in GitHub Desktop.
Save kylebutts/0511de9eb935b65cdc752454322c186b to your computer and use it in GitHub Desktop.
htmx + R example
library(htmltools)
#* @serializer html
#* @get /
base = function() {
html <- tags$html(
tags$head(
tags$script(src='https://unpkg.com/htmx.org@1.9.10/dist/htmx.js')
),
tags$body(
tags$button(
'hx-post'="/clicked",
'hx-swap'="outerHTML",
"Click Me"
)
)
)
html |> doRenderTags()
}
#* @serializer html
#* @post /clicked
clicked = function() {
htmltools::h1("I'm clicked") |>
doRenderTags()
}
library(plumber)
pr_run(pr("apis.R"), port = 8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment