Title: | ambhtmx |
---|---|
Description: | Build a Full-stack R App with ambiorix and htmx. |
Authors: | Jordi Rosell [aut, cre] |
Maintainer: | Jordi Rosell <[email protected]> |
License: | CC0 |
Version: | 0.0.0.9003 |
Built: | 2024-11-17 05:58:03 UTC |
Source: | https://github.com/jrosell/ambhtmx |
Generate component
amb_card( ..., class = NULL, title = NULL, title_icon = NULL, title_class = NULL ) amb_input_text( ..., id, label = NULL, value = "", input_class = NULL, hx_post = NULL ) amb_button(..., class = "rounded-1", type = "button") amb_htmlwidget(widget, ..., width = "100%", height = "400px")
amb_card( ..., class = NULL, title = NULL, title_icon = NULL, title_class = NULL ) amb_input_text( ..., id, label = NULL, value = "", input_class = NULL, hx_post = NULL ) amb_button(..., class = "rounded-1", type = "button") amb_htmlwidget(widget, ..., width = "100%", height = "400px")
... |
attributes to add to the container |
class |
customize |
title |
to customeize the title text |
title_icon |
to customize the title icon |
title_class |
to add more classes to the title |
id |
for the label and the input |
label |
customize |
value |
customize |
input_class |
customize |
hx_post |
customize |
type |
customize |
widget |
htmlwidget to convert as a shiny.tag |
width |
to customeize the width of the container |
height |
to customeize the width of the container |
Creating an ambiorix + htmx app
ambhtmx( dbname = NULL, value = tibble::tibble(), protocol = NULL, host = NULL, port = NULL, live = "", favicon = NULL, render_index = NULL, render_row = NULL )
ambhtmx( dbname = NULL, value = tibble::tibble(), protocol = NULL, host = NULL, port = NULL, live = "", favicon = NULL, render_index = NULL, render_row = NULL )
dbname |
file path to store a SQLite database (optional). |
value |
a 1 row tibble with the names and types of the columns (optional) |
protocol |
(default AMBHTMX_PROTOCOL or http) |
host |
(default AMBHTMX_HOST or 127.0.0.1) |
port |
(default AMBHTMX_PORT or 3000) |
live |
script with the file path (optional) |
favicon |
(optional) |
render_index |
function to be stored as a model method (optional) |
render_row |
function to be stored as a model method (optional) |
A list with the ambiorix app, the running context and the model methods.
Process error get requests
process_error_get(req, res, cookie_errors = "errors")
process_error_get(req, res, cookie_errors = "errors")
req |
request object |
res |
response object |
cookie_errors |
if you need to customize the name of the errors cookie |
the error character vector
Process loggedin middleware
process_loggedin_middleware( req, res, user = Sys.getenv("AMBHTMX_USER"), cookie_loggedin = "loggedin" )
process_loggedin_middleware( req, res, user = Sys.getenv("AMBHTMX_USER"), cookie_loggedin = "loggedin" )
req |
request object |
res |
response object |
user |
if you want to customize the required user or it uses AMBHTMX_USER |
cookie_loggedin |
if you need to customize the name of the loggedin cookie |
the updated request with the req$loggedin status
Render and send login page response
process_login_get( req, res, page_title = "Login", main = NULL, id = "login_form", login_url = "/login", style = "margin: 20px", cookie_errors = "errors" )
process_login_get( req, res, page_title = "Login", main = NULL, id = "login_form", login_url = "/login", style = "margin: 20px", cookie_errors = "errors" )
req |
request object |
res |
response object |
page_title |
if you need to customize the title of the page |
main |
if you need to customize the body of the login page |
id |
if you need to customize the id of the login form |
login_url |
if you need to customize the url of the login form |
style |
if you need to customize the styles of the login form |
cookie_errors |
if you need to customize the name of the errors cookie |
the login page response
Process login requests
process_login_post( req, res, user_param = "user", password_param = "password", user = Sys.getenv("AMBHTMX_USER"), password = Sys.getenv("AMBHTMX_PASSWORD"), user_error = "Invalid user", password_error = "Invalid password", cookie_loggedin = "loggedin", cookie_errors = "errors", login_url = "/login", success_url = "/" )
process_login_post( req, res, user_param = "user", password_param = "password", user = Sys.getenv("AMBHTMX_USER"), password = Sys.getenv("AMBHTMX_PASSWORD"), user_error = "Invalid user", password_error = "Invalid password", cookie_loggedin = "loggedin", cookie_errors = "errors", login_url = "/login", success_url = "/" )
req |
request object |
res |
response object |
user_param |
if you need to customize the name of the user parameter |
password_param |
if you need to customize the name of the password parameter |
user |
if you want to customize the required user or it uses AMBHTMX_USER |
password |
if you want to customize the required password or it uses AMBHTMX_PASSWORD |
user_error |
if you need to customize the error message for the user |
password_error |
if you need to customize the error message for the password |
cookie_loggedin |
if you need to customize the name of the loggedin cookie |
cookie_errors |
if you need to customize the name of the errors cookie |
login_url |
if you need to customize the url of the login form |
success_url |
if you need to customize the url of the success loggedin process |
the login process response
Process logout requests
process_logout_get(req, res, cookie_loggedin = "loggedin", success_url = "/")
process_logout_get(req, res, cookie_loggedin = "loggedin", success_url = "/")
req |
request object |
res |
response object |
cookie_loggedin |
if you need to customize the name of the loggedin cookie |
success_url |
if you need to customize the url of the success loggedin process |
the logout process response
Render a custom page with a custom title and main content
render_page(main = NULL, page_title = NULL, head_tags = NULL)
render_page(main = NULL, page_title = NULL, head_tags = NULL)
main |
htmltools object of the body of the html page |
page_title |
the title tag contents of the page |
head_tags |
optional htmltools object of the head of the html page |
It can throw exceptions, so handling exceptions is recommended, if not a must.
the rendered html of the full html page with dependencies
Render a png image to a img tag
render_png(p)
render_png(p)
p |
a ggplot or another object that can be printed and captured as a png image |
img htmltools tag with a data encoded src attribute
Render tags to character vector
render_tags(...)
render_tags(...)
... |
one or more htmltools objects. |
a character representation of input
Generate script from js template
script_from_js_tpl(file, ...)
script_from_js_tpl(file, ...)
file |
path to a js file |
... |
mutiple named arguments with the value to replace |
if (FALSE){ # replaces {init} to 0 script_from_js_tpl("script.js", init = "init") }
if (FALSE){ # replaces {init} to 0 script_from_js_tpl("script.js", init = "init") }
Generate script from raw js template
script_tpl(raw_content, ...)
script_tpl(raw_content, ...)
raw_content |
path to a js file |
... |
mutiple named arguments with the value to replace |
Render a page and send the respose
send_page(main = NULL, res, ...)
send_page(main = NULL, res, ...)
main |
htmltools object of the body of the html page |
res |
response object |
... |
other paramters to the render page function |
Render a custom page with a custom title and main content
send_tags(main = NULL, res, ...)
send_tags(main = NULL, res, ...)
main |
htmltools object to render |
res |
response object |
... |
htmltools object to render |
Generate style from css template
style_from_css_tpl(file, ...)
style_from_css_tpl(file, ...)
file |
path to a css file |
... |
mutiple named arguments with the value to replaces |
if (FALSE){ # replaces "var(--tpl-background)" to "red" style_from_css_tpl("styles.css", background = "red") }
if (FALSE){ # replaces "var(--tpl-background)" to "red" style_from_css_tpl("styles.css", background = "red") }
Generate style from raw css
style_tpl(raw_content, ...)
style_tpl(raw_content, ...)
raw_content |
contents with tpl in css |
... |
mutiple named arguments with the value to replaces |
Create an R object that represents an HTML tag. For convenience, common HTML
tags (e.g., <div>
) can be created by calling for their tag name directly
(e.g., div()
). To create less common HTML5 (or SVG) tags (e.g.,
<article>
), use the tags
list collection (e.g., tags$article()
). To
create other non HTML/SVG tags, use the lower-level tag()
constructor.
button(..., .noWS = NULL, .renderHook = NULL) textarea(..., .noWS = NULL, .renderHook = NULL) input(..., .noWS = NULL, .renderHook = NULL) label(..., .noWS = NULL, .renderHook = NULL) nav(..., .noWS = NULL, .renderHook = NULL) li(..., .noWS = NULL, .renderHook = NULL) ul(..., .noWS = NULL, .renderHook = NULL) ol(..., .noWS = NULL, .renderHook = NULL) form(..., .noWS = NULL, .renderHook = NULL) style(..., .noWS = NULL, .renderHook = NULL) script(..., .noWS = NULL, .renderHook = NULL)
button(..., .noWS = NULL, .renderHook = NULL) textarea(..., .noWS = NULL, .renderHook = NULL) input(..., .noWS = NULL, .renderHook = NULL) label(..., .noWS = NULL, .renderHook = NULL) nav(..., .noWS = NULL, .renderHook = NULL) li(..., .noWS = NULL, .renderHook = NULL) ul(..., .noWS = NULL, .renderHook = NULL) ol(..., .noWS = NULL, .renderHook = NULL) form(..., .noWS = NULL, .renderHook = NULL) style(..., .noWS = NULL, .renderHook = NULL) script(..., .noWS = NULL, .renderHook = NULL)
... |
Tag attributes (named arguments) and children (unnamed arguments).
A named argument with an
|
.noWS |
Character vector used to omit some of the whitespace that would
normally be written around this tag. Valid options include |
.renderHook |
A function (or list of functions) to call when the |
A list()
with a shiny.tag
class that can be converted into an
HTML string via as.character()
and saved to a file with save_html()
.