Title: | Companion Package for JavaScript for Shiny Users |
---|---|
Description: | Companion Package for JavaScript for Shiny Users. |
Authors: | Garrick Aden-Buie [aut, cre] |
Maintainer: | Garrick Aden-Buie <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.28 |
Built: | 2024-11-20 04:20:44 UTC |
Source: | https://github.com/gadenbuie/js4shiny |
First sentences of books, downloaded from https://firstsentencesofbooks.tumblr.com/.
first_sentences
first_sentences
A data frame with 40 rows and 3 variables:
quote
The first sentence of the book
title
The title of the book
author
The author of the book
Include the various HTML JavaScript and CSS assets created for js4shiny.
html_dependency_js4shiny( redirectConsole = TRUE, jsonview = TRUE, stylize = "all", use_google_fonts = FALSE ) html_dependency_redirectConsoleLog() html_dependency_stylize(...)
html_dependency_js4shiny( redirectConsole = TRUE, jsonview = TRUE, stylize = "all", use_google_fonts = FALSE ) html_dependency_redirectConsoleLog() html_dependency_stylize(...)
redirectConsole |
Include JS and CSS assets to enable literate
programming with JavaScript by redirecting |
jsonview |
Include JS and CSS assets to enable tree view display of JSON objects for the knitr json engine. |
stylize |
One of "none", "all", "fonts", "variables", "table", "utility", "code", "pandoc-line-numbers" to include the CSS styles developed for js4shiny. |
use_google_fonts |
Should fonts hosted on Google Fonts be included?
Default is |
... |
Arguments passed to |
html_dependency_redirectConsoleLog
: Include just the console redirection
dependencies.
html_dependency_stylize
: Include the full or partial
js4shiny CSS styles.
Other js4shiny HTML dependencies:
html_setup()
An R Markdown format for literate JavaScript programming. With
default settings, each JavaScript chunk is run in its own environment and
any output written with console.log()
is inserted in the HTML document as
the code runs. In this setting, the JavaScript is rendered directly in the
browser at view time.
A similar effect can be achieved by using the js_live = FALSE
chunk option
to instead run the JavaScript code using node
at compile time. In this
setting, the results printed by the node
process are captured and stored in
the document, resulting in a non-dynamic output that captures the results of
the JavaScript runtime code.
In both of the above settings, each code chunk is run separately. You can use
the js_redirect = FALSE
knitr chunk option to disable the console.log()
redirect and use the standard JavaScript engine included in the knitr
package. Logged statements will still be available in the browser's
devolper tools console, as this engine is equivalent to having entered
the JavaScript code directly into the HTML source within a <script>
tag.
html_document_js( ..., theme = NULL, css = NULL, toc = FALSE, toc_depth = 3, mathjax = NULL, use_fontawesome = FALSE, use_google_fonts = FALSE, highlight = "haddock", fig_width = 10, fig_height = 7, fig_retina = 2, keep_md = FALSE, dev = "png", pandoc_args = NULL, extra_dependencies = NULL )
html_document_js( ..., theme = NULL, css = NULL, toc = FALSE, toc_depth = 3, mathjax = NULL, use_fontawesome = FALSE, use_google_fonts = FALSE, highlight = "haddock", fig_width = 10, fig_height = 7, fig_retina = 2, keep_md = FALSE, dev = "png", pandoc_args = NULL, extra_dependencies = NULL )
... |
Additional function arguments to pass to the
base R Markdown HTML output formatter |
theme |
Ignored |
css |
One or more css files to include |
toc |
|
toc_depth |
Depth of headers to include in table of contents |
mathjax |
Include mathjax. The "default" option uses an https URL from a
MathJax CDN. The "local" option uses a local version of MathJax (which is
copied into the output directory). You can pass an alternate URL or pass
|
use_fontawesome |
Should FontAwesome be included? Default is |
use_google_fonts |
Should fonts hosted on Google Fonts be included?
Default is |
highlight |
One of the pandoc highlight styles. |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
keep_md |
Keep the markdown file generated by knitting. |
dev |
Graphics device to use for figure output (defaults to png) |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
Additional function arguments to pass to the
base R Markdown HTML output formatter |
This document type is built on the html_document_plain()
, but is configured
to render the example documents created by the repl()
. You may choose to
render the solution or the example's initial state by setting the output
option version
.
html_document_js4shiny(version = c("solution", "initial"), ...)
html_document_js4shiny(version = c("solution", "initial"), ...)
version |
Which version of the example to render. One of |
... |
Additional arguments passed to |
html_document_plain()
html_document_js()
if (rmarkdown::pandoc_available("1.12.3")) { css_ex <- system.file( "examples", "css", "css-basics", "css-basics-appearance.Rmd", package = "js4shiny" ) tmp_html_init <- tempfile("initial", fileext = ".html") tmp_html_sol <- tempfile("solution", fileext = ".html") tmp_html_init <- rmarkdown::render( input = css_ex, output_file = tmp_html_init, output_options = list(version = "initial"), quiet = TRUE ) tmp_html_sol <- rmarkdown::render( input = css_ex, output_file = tmp_html_sol, output_options = list(version = "solution"), quiet = TRUE ) } # View tmp_html_init/sol # browseURL(tmp_html_init) # browseURL(tmp_html_sol)
if (rmarkdown::pandoc_available("1.12.3")) { css_ex <- system.file( "examples", "css", "css-basics", "css-basics-appearance.Rmd", package = "js4shiny" ) tmp_html_init <- tempfile("initial", fileext = ".html") tmp_html_sol <- tempfile("solution", fileext = ".html") tmp_html_init <- rmarkdown::render( input = css_ex, output_file = tmp_html_init, output_options = list(version = "initial"), quiet = TRUE ) tmp_html_sol <- rmarkdown::render( input = css_ex, output_file = tmp_html_sol, output_options = list(version = "solution"), quiet = TRUE ) } # View tmp_html_init/sol # browseURL(tmp_html_init) # browseURL(tmp_html_sol)
This RMarkdown output format provides a minimal HTML5 template and minimal features for including CSS and JavaScript files in the output source.
html_document_plain( ..., css = "normalize", script = NULL, highlight = "haddock", fig_width = 10, fig_height = 7, fig_retina = 2, keep_md = FALSE, dev = "png", pandoc_args = NULL, extra_dependencies = NULL ) include_script(head = NULL, before = NULL, after = NULL)
html_document_plain( ..., css = "normalize", script = NULL, highlight = "haddock", fig_width = 10, fig_height = 7, fig_retina = 2, keep_md = FALSE, dev = "png", pandoc_args = NULL, extra_dependencies = NULL ) include_script(head = NULL, before = NULL, after = NULL)
... |
Additional function arguments to pass to the
base R Markdown HTML output formatter |
css |
A list of css files to include in the document's |
script |
A list of |
highlight |
One of the pandoc highlight styles. |
fig_width |
Default width (in inches) for figures |
fig_height |
Default height (in inches) for figures |
fig_retina |
Scaling to perform for retina displays (defaults to 2, which
currently works for all widely used retina displays). Set to |
keep_md |
Keep the markdown file generated by knitting. |
dev |
Graphics device to use for figure output (defaults to png) |
pandoc_args |
Additional command line options to pass to pandoc |
extra_dependencies |
Additional function arguments to pass to the
base R Markdown HTML output formatter |
head , before , after
|
A character vector of source files, each to be
included in the |
include_script
: Helper function for including JS scripts
Overrides the JavaScript knitr engine, registers knitr output hooks, and declares the JS and CSS dependencies that are required to enable the literate JavaScript code chunks inside R Markdown formats that write to HTML.
html_setup(stylize = "none") html_setup_blogdown( stylize = c("fonts", "variables", "table", "code", "utility") )
html_setup(stylize = "none") html_setup_blogdown( stylize = c("fonts", "variables", "table", "code", "utility") )
stylize |
One of "none", "all", "fonts", "variables", "table", "utility", "code", "pandoc-line-numbers" to include the CSS styles developed for js4shiny. |
html_setup_blogdown
: A blogdown-specific HTML setup that includes styles
for <pre>
code blocks, tables, some utility functions, and the CSS
variables declaring the js4shiny colors.
Other js4shiny HTML dependencies:
html_dependency_js4shiny()
Opens or creates an R Markdown document using the js4shiny html document templates.
js4shiny_rmd( type = c("plain", "js"), full_template = FALSE, path = NULL, overwrite = FALSE )
js4shiny_rmd( type = c("plain", "js"), full_template = FALSE, path = NULL, overwrite = FALSE )
type |
One of |
full_template |
Include the full R Markdown template document. Default
is |
path |
If |
overwrite |
If |
html_document_plain()
, html_document_js()
tmpfile <- tempfile(fileext = ".Rmd") js4shiny_rmd(type = "plain", full_template = TRUE, path = tmpfile) js4shiny_rmd(type = "plain", path = tmpfile, overwrite = TRUE)
tmpfile <- tempfile(fileext = ".Rmd") js4shiny_rmd(type = "plain", full_template = TRUE, path = tmpfile) js4shiny_rmd(type = "plain", path = tmpfile, overwrite = TRUE)
A JavaScript Engine for knitr
knitr_js_engine()
knitr_js_engine()
This function sets the shiny.launch.browser
option to launch Shiny apps in
an "external"
browser, the RStudio viewer "pane"
, or a new "window"
in
RStudio.
launch_shiny_in(where = NULL)
launch_shiny_in(where = NULL)
where |
One of |
This addin lints and fixes selected JavaScript code or the currently open
file in RStudio. The addin can be helpful for linting JavaScript code
embedded in R Markdown or Shiny apps, in addition to linting whole JavaScript
files. The underlying functions are not exported from js4shiny. If you
want to programmatically lint multiple files, it would be better to use npm
scripts or another JavaScript task running system to lint your files.
standardjs is a
style guide, code linter, and beautifier in one. It is also a command line
tool (standard
) for automatically formatting JavaScript code in the
JavaScript Standard Style. The command line tool
will also alert users to common style and programmer errors.
Using standard
and this addin requires that node
, npm
, and standard
be installed on your system. To install node
and npm
, you need to
install Node.js (they come together). Follow the instructions from Node.js to install these tools. Confirm
that your installation was successful by running npm -v
in a new terminal
session. Once npm
is available, install standard
globally by running
this command in the terminal.
npm install standard --global
https://standardjs.com/
Opens a live preview of the files in a directory. The live preview server
automatically renders R Markdown files when they are saved, and the preview
is refreshed whenever R Markdown files or supporting files, such as .js
,
.css
, .htm
, .html
, .sass
, or .scss
files, are updated. This
functionality requires the servr package.
live_preview( path = getwd(), update_pattern = "[.](js|css|[Rr]?[Mm][Dd]|html?|s[ca]ss)$", ..., render_quietly = getOption("js4shiny.live_preview.quiet", TRUE), external = FALSE ) live_preview_stop(which = NULL)
live_preview( path = getwd(), update_pattern = "[.](js|css|[Rr]?[Mm][Dd]|html?|s[ca]ss)$", ..., render_quietly = getOption("js4shiny.live_preview.quiet", TRUE), external = FALSE ) live_preview_stop(which = NULL)
path |
The path for the directory or file to preview. If the path given is an R Markdown document or HTML document, the HTML version of that file will be opened directly, otherwise the directory containing the file will be served. |
update_pattern |
Update the live preview when files matching this
pattern are updated. By default, updating files with the following
extensions will update the preview: |
... |
Arguments passed on to
|
render_quietly |
If
|
external |
Should the live preview be opened in an external browser?
The default is |
which |
A integer vector of the server IDs; by default, IDs of all
existing servers in the current R session obtained from
|
Invisibly returns the servr::httw()
object, so that you can
manually stop the server with the $stop_server()
method.
live_preview_stop
: Stop the live preview background daemons. See
servr::daemon_list()
for more information.
There are three Live Preview addins provided by js4shiny. Live Preview and Live Preview (External) open a live preview of the directory of the currently open document, if possible at the current HTML document corresponding to the open document. The external preview addin automatically opens the preview in your web browser, otherwise the preview is opened in the RStudio Viewer pane.
To stop the live server, you can call servr::daemon_stop()
or
live_preview_stop()
, which will stop all bakground servr daemons,
or you can use the Live Preview Stop addin.
if (interactive()) { tmp_dir <- tempfile("live-preview") dir.create(tmp_dir) tmp_rmd <- file.path(tmp_dir, "js4shiny-plain.Rmd") # Create a new js4shiny plain HTML document. If interactive # and in RStudio, this file will open and you can use the # addins to launch the live preview js4shiny_rmd("js", full_template = TRUE, path = tmp_rmd) srvr <- live_preview(tmp_rmd) # Stop all background servers with either of the following # live_preview_stop() # servr::daemon_stop() # # Or if you've saved the return value from live_preview() # srvr$stop_server() }
if (interactive()) { tmp_dir <- tempfile("live-preview") dir.create(tmp_dir) tmp_rmd <- file.path(tmp_dir, "js4shiny-plain.Rmd") # Create a new js4shiny plain HTML document. If interactive # and in RStudio, this file will open and you can use the # addins to launch the live preview js4shiny_rmd("js", full_template = TRUE, path = tmp_rmd) srvr <- live_preview(tmp_rmd) # Stop all background servers with either of the following # live_preview_stop() # servr::daemon_stop() # # Or if you've saved the return value from live_preview() # srvr$stop_server() }
Searches the MDN Web Docs for a search term. Includes an RStudio addin for quick and seamless searching: highlight a term in the source code and run the addin to search MDN. If no text is highlighted, the addin opens a Shiny gadget for you to enter your search term.
mdn_search( term, browse = TRUE, topics = c("js", "api", "css", "html", "svg"), locale = "en-US" ) mdn_gadget(browse = TRUE, locale = NULL)
mdn_search( term, browse = TRUE, topics = c("js", "api", "css", "html", "svg"), locale = "en-US" ) mdn_gadget(browse = TRUE, locale = NULL)
term |
Search term |
browse |
Should the search results be opened in a browser window? If not, the URL is returned instead. |
topics |
A selection of topics to search, choosing from |
locale |
The locale string for the search query. Default is |
The search URL
mdn_gadget
: A Shiny gadget for searching the MDN docs.
Register the js4shiny knitr JavaScript engine or the output hooks. Generally,
you will not need to use these. Instead, see html_document_js()
or
html_setup()
for methods that cover most use-cases.
register_knitr_output_hooks(set = TRUE, chunk_hook = NULL) register_knitr_js_engine(set = TRUE)
register_knitr_output_hooks(set = TRUE, chunk_hook = NULL) register_knitr_js_engine(set = TRUE)
set |
If |
chunk_hook |
Chunk hook to be applied after the js4shiny chunk hook
is applied to the chunk output. If |
Launches an interactive Shiny app for live editing of frontend JavaScript,
CSS, and HTML/Markdown/R Markdown. The app allows users to write JS, CSS and
HTML, preview the final product, observe the JavaScript console (specifically
items printed to the console via console.log()
), and download a zip file
containing the source files.
repl_example(example = NULL) repl( example = NULL, js_repl_only = FALSE, theme_app = NULL, theme_editor = "textmate", autocomplete = c("css", "html"), render_dir = NULL, options = list(), ... ) repl_js(..., render_dir = NULL)
repl_example(example = NULL) repl( example = NULL, js_repl_only = FALSE, theme_app = NULL, theme_editor = "textmate", autocomplete = c("css", "html"), render_dir = NULL, options = list(), ... ) repl_js(..., render_dir = NULL)
example |
The short name of the exercise or example, e.g.
|
js_repl_only |
When |
theme_app |
The theme of the app, using shinythemes. See
|
theme_editor |
The theme of the shinyAce source code editors. See
|
autocomplete |
Ace Editor language modes for which autocomplete will be
enabled. One or more of |
render_dir |
Where to render temporary files, defaults to |
options |
Options passed to |
... |
Arguments passed from |
A shiny app
repl_example
: Launch a js4shiny exercise or example using the
example slug, or the full filename. If none provided, repl_example()
launches an interactive example browser.
The app was developed for the js4shiny rstudio::conf workshop and can be used to load examples for practicing and learning JavaScript and web development concepts.
This function installs a set of R, HTML, JavaScript and CSS snippets that are helpful when developing Shiny apps and doing web development work in RStudio. By default, the snippets are installed where RStudio will find them. If you haven't previously installed snippets to RStudio, these snippets will mask some of the built-in snippets that ship with RStudio.
snippets_install(install_path = NULL, update = TRUE)
snippets_install(install_path = NULL, update = TRUE)
install_path |
Where should the snippets be installed? If |
update |
Should existing snippets be updated in place if there are any
conflicts? Default is yes ( |
If you already have snippets installed,
you can you can have the installed snippets update the existing snippets
in place with update = TRUE
. Or you can append the new snippets to the
existing snippets files with update = FALSE
. This option is desirable if
you want to make sure that no snippets are overwritten. The newer snippets
will mask older snippets, but no data will be lost.
snip_tmp <- tempfile("snippets") dir.create(snip_tmp) snippets_install(snip_tmp)
snip_tmp <- tempfile("snippets") dir.create(snip_tmp) snippets_install(snip_tmp)
A ranking by U.S. news of the 125 most populous US metro areas to find the best places to live.
us_cities_ranked
us_cities_ranked
A data frame with 125 rows and 26 variables:
us_news_rank
integer. Ranking by U.S. News
city
character. City name
state
character. State name, abbreviated
state_full
character. State name, full
metro_population
double. Population of meto area
average_annual_salary
double. Average annual salary
avg_temp_high_f
double. Average high temperature in ºF
avg_temp_low_f
double. Average low temperature in ºF
median_age
double. Median population age
median_home_price
double. Median home price
avg_annual_rainfall_in
double. Average annual rainfall in inches
unemployment_rate
double. Unemployment rate
median_monthly_rent
double. Median monthly rent cost
avg_commute_time_mins
double. Average commute times in minutes
percent_single
double. Percent of metro population that is single
total_students
double. Total number of students
total_teachers
double. Total number of teaches
violent_crime
double. Crime rates per 100,000 people
property_crime
double. Crime rates per 100,000 people
link
character. Link to url on usanews.com
lat
double. Latitude of metro area
lon
double. Longitude of metro area
lat_min
double. Latitude minimum bounding box of metro area
lat_max
double. Latitude maximum bounding box of metro area
lon_min
double. Longitude minimum bounding box of metro area
lon_max
double. Longitude maximum bounding box of metro area
https://data.world/dataremixed/125-us-cities-ranked-2019, https://realestate.usnews.com/places/rankings/best-places-to-live