Learn R Programming

r2resize (version 2.0)

add.JQuery: Attach jQuery to an HTML Document for r2resize Components

Description

This function dynamically includes the jQuery library into an HTML output. It's particularly useful when other functions within the `r2resize` package, which rely on jQuery, are used in an environment (like a knitted R Markdown document or a Shiny application) where jQuery might not be automatically present or where a specific version is required.

Usage

add.JQuery(version = "3.5.1")

Value

An HTML `<script>` tag as a character string, with `html` and `character` classes, containing the link to the jQuery library.

Arguments

version

A character string specifying the desired jQuery version (e.g., "3.5.1", "3.7.0"). Defaults to "3.5.1" if no version is provided. Ensure the version specified is available on the jQuery CDN.

Details

The `add.JQuery` function generates a `<script>` HTML tag that links to a specified version of the jQuery library from a Content Delivery Network (CDN). By calling this function, you ensure that the necessary jQuery functionalities are available for `r2resize`'s interactive components, such as those used in `splitCard`, `sizeableCard`, or `windowCard`. This function adds the `html` and `character` classes to the output, making it compatible with `htmltools::htmlDependency` and other HTML rendering contexts in R.

See Also

splitCard for an example of a `r2resize` component that might rely on jQuery.

Examples

Run this code
# Attach the default jQuery version (3.5.1)
r2resize::add.JQuery()

# Attach a specific jQuery version (e.g., 3.7.0)
r2resize::add.JQuery("3.7.0")

# This function is often used implicitly by other r2resize components,
# but can be manually added to ensure jQuery is present in a custom HTML context.

# Example in a simple R Markdown chunk (won't render fully without proper setup)
if (FALSE) {
r2resize::add.JQuery()
htmltools::div("This text requires jQuery for some interactive features.")
}

Run the code above in your browser using DataLab