Created
March 13, 2024 21:10
-
-
Save kylebutts/0511de9eb935b65cdc752454322c186b to your computer and use it in GitHub Desktop.
htmx + R example
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
| 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() | |
| } |
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
| 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