Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tagQuery() docs; Add .cssSelector parameter to tag methods #224

Merged
merged 41 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fb851a4
wip mainly improve tagQuery() docs
cpsievert Apr 20, 2021
55bebce
wip flesh out article
cpsievert Apr 21, 2021
40076b9
Merge branch 'master' into tagQueryDocs
cpsievert Apr 21, 2021
df0a110
Fix the broken method details
cpsievert Apr 21, 2021
3f03d6d
More vignette improvements
cpsievert Apr 21, 2021
fc4cb44
Merge branch 'master' into tagQueryDocs
cpsievert Apr 21, 2021
bacbbe1
Merge branch 'master' into tagQueryDocs
cpsievert Apr 21, 2021
3d1b187
wip basic pkgdown site and readme
cpsievert Apr 22, 2021
7d34898
Merge branch 'master' into tagQueryDocs
cpsievert Apr 22, 2021
68da5e0
put replace methods into their own section
cpsievert Apr 22, 2021
b51f66d
ignore vignettes; roxygenize
cpsievert May 4, 2021
738c3ce
Merge branch 'master' into tagQueryDocs
cpsievert May 4, 2021
ae33aad
Update R/tag_query.R
cpsievert May 4, 2021
e41578d
code review
cpsievert May 4, 2021
b4515d6
fix incorrect merge conflict
cpsievert May 4, 2021
bf72fa4
Show R console output when printing tags/tagLists
cpsievert May 4, 2021
910b1ab
Improve code example output
cpsievert May 4, 2021
9be505e
Merge branch 'master' into tagQueryDocs
cpsievert May 4, 2021
a419f9e
fix weird conflict issue
cpsievert May 4, 2021
592a13f
Just use a README.md
cpsievert May 4, 2021
d9b909e
Merge branch 'master' into tagQueryDocs
cpsievert May 5, 2021
fbe4210
Merge branch 'master' into tagQueryDocs
cpsievert May 5, 2021
0e3f820
Update README.md
schloerke May 5, 2021
5c23fd2
Add "Getting Started" article which redirects to Shiny custom html ar…
schloerke May 5, 2021
646d78b
Merge branch 'master' into tagQueryDocs
schloerke May 5, 2021
0b67ac2
Initialize hex sticker (#246)
schloerke May 6, 2021
692f348
Remove "All Vignettes" header from Articles page
schloerke May 6, 2021
cf285c4
Comment development mode and set to auto
schloerke May 6, 2021
4672846
Do not flatten tag attribs here
schloerke May 10, 2021
2b0a0a8
Add performance section draft
schloerke May 10, 2021
fe80dca
Install `microbenchmark`
schloerke May 10, 2021
29e75ca
Add .cssSelector arg to 'top-level' append functions; add docs
cpsievert May 11, 2021
2c95a28
Improve tag creation and modifier Rd docs
cpsievert May 11, 2021
3007011
Bump version
cpsievert May 12, 2021
be01bdc
Merge branch 'master' into tagQueryDocs
schloerke May 13, 2021
a336cf3
Add `.cssSelector` tests for standard tag methods.
schloerke May 13, 2021
0be6fda
Fix missing magrittr library call
schloerke May 13, 2021
bc2d81e
Adjust width and add note about `$children` being flattened
schloerke May 13, 2021
acdb496
Add `Modify tags` section with `tagAppendChild` and `tagAppendAttribu…
schloerke May 13, 2021
90063fc
Clarification on speed
schloerke May 13, 2021
f1d53f7
Install `bench` instead of `microbenchmark`
schloerke May 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^vignettes$
^logo$
4 changes: 3 additions & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
run: |
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
saveRDS(pak::pkg_deps_tree("local::.", dependencies = TRUE), ".github/r-depends.rds")
pak::pkg_install("rstudio/quillt")
- name: Cache R packages
uses: actions/cache@v2
with:
Expand All @@ -49,12 +50,13 @@ jobs:
run: |
pak::local_system_requirements(execute = TRUE)
pak::pkg_system_requirements("pkgdown", execute = TRUE)
pak::pkg_system_requirements("microbenchmark", execute = TRUE)

- name: Install dependencies
shell: Rscript {0}
run: |
pak::local_install_dev_deps(upgrade = TRUE)
pak::pkg_install("pkgdown")
pak::pkg_install(c("pkgdown", "microbenchmark"), upgrade = TRUE)

- name: Install package
run: R CMD INSTALL .
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## New Features & Improvements

* Added `tagQuery(tags)`. A tag query object implements many popular features of jQuery. Similar to jQuery, tag query objects can find internal html using CSS selections. Given a selection (which defaults to the original `tags`), many alterations may be performed before converting the tag query object back to tag objects. (#208)
* `{htmltools}` now has its own `{pkgdown}` site hosted at <https://rstudio.github.io/htmltools/>.

* The new `tagQuery()` function provides a [jQuery](https://jquery.com/) inspired interface to query and/or modify HTML `tag()` (e.g., `div()`) or `tagList()` objects. To learn more, see the [{pkgdown} article](https://rstudio.github.io/htmltools/articles/tagQuery.html). (#208)

* Added `tagAddRenderHook()` for delaying modification of a tag object until it is rendered. A list of render-time hooks may also be added via the new `.renderHook` argument added to all `tag()` functions. (#215)

Expand Down
7 changes: 0 additions & 7 deletions R/selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ asSelector <- function(selector) {
)
}

# if it contains multiple elements, recurse
if (txt_detect(selector, "* ", fixed = TRUE)) {
# we already match on all elements. No need to know about this selector
warning("Removing `* ` from selector. ")
selector <- txt_remove_all(selector, "* ", fixed = TRUE)
}

# Check here to avoid inf recursion
if (txt_detect(selector, ">", fixed = TRUE)) {
# If there is a `>`, pad it with spaces
Expand Down
389 changes: 129 additions & 260 deletions R/tag_query.R

Large diffs are not rendered by default.

52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# htmltools

<!-- badges: start -->

[![R build
status](https://github.com/rstudio/htmltools/workflows/R-CMD-check/badge.svg)](https://github.com/rstudio/htmltools)
[![CRAN
Expand All @@ -13,4 +10,51 @@ Downloads](https://cranlogs.r-pkg.org/badges/grand-total/htmltools)](https://www
experimental](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
<!-- badges: end -->

Tools for HTML generation and output.
# htmltools <a href='https://rstudio.github.io/htmltools'><img src='man/figures/logo.png' align="right" height="138" /></a>

Tools for creating, manipulating, and writing HTML from R.

## Installation

Install the stable release of `htmltools` on CRAN:

```r
install.packages("htmltools")
```

Install the development version with:

```r
remotes::install_github("rstudio/htmltools")
```

## Quick overview

`{htmltools}` makes it easy to customize the user interface (UI) of any [Shiny](https://shiny.rstudio.com/) or [R Markdown](https://rmarkdown.rstudio.com/) project by using R code to generate custom HTML (including JavaScript and CSS).

[This Shiny article](https://shiny.rstudio.com/articles/html-tags.html) provides a great introduction to `{htmltools}` (even if you're not interested in Shiny). As you'll learn in that article, the general foundation that `{htmltools}` provides allows other R packages (e.g., [`{htmlwidgets}`](http://www.htmlwidgets.org/), [`{crosstalk}`](https://rstudio.github.io/crosstalk/), etc.) to provide "HTML components" in R that users can manipulate and combine in ways the component authors didn't foresee.

For example, as described in depth [here](https://plotly-r.com/arranging-views.html#arranging-htmlwidgets), `{htmltools}` makes it fairly easy to arrange numerous `{htmlwidgets}` (e.g., `{plotly}` graphs) into a single static HTML webpage:

```r
library(htmltools)
browsable(tagList(
plot_ly(diamonds, x = ~carat, height = 200),
plot_ly(diamonds, x = ~price, height = 200)
))
```

<div align="center">
<img src="man/figures/plotly-taglist.png" width="60%" />
</div>

Also, thanks to `tagQuery()`, it fairly easy to query and manipulate the underlying HTML structure of components. See the [`tagQuery()` article](https://rstudio.github.io/htmltools/articles/tagQuery.html) to learn more.


## Learn more

If you're looking to learn how to build more custom user interfaces by writing custom HTML/JavaScript/CSS, we recommend the following resource:

* Shiny's [UI](https://shiny.rstudio.com/articles/#user-interface) and [extensions](https://shiny.rstudio.com/articles/#extensions) articles
* [Outstanding UI with Shiny](https://unleash-shiny.rinterface.com/) by David Granjon
* [JavaScript for R](https://book.javascript-for-r.com/) by John Coene
1 change: 1 addition & 0 deletions logo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
old
Binary file added logo/htmltools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions logo/htmltools.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions logo/htmltools_src.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/plotly-taglist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading