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

Bug fix for script parsing #98

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ tools/gallery-template.Rmd
^\.github$
^codecov\.yml$
^docs$
^cran-comments\.md$
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: r2d3
Type: Package
Title: Interface to 'D3' Visualizations
Version: 0.2.5
Version: 0.2.6
Authors@R: c(
person("Nick", "Strayer", email = "[email protected]", role = c("aut", "cre")),
person("Javier", "Luraschi", email = "[email protected]", role = c("aut")),
person("JJ", "Allaire", role = c("aut")),
person("Mike", "Bostock", role = c("ctb", "cph"), comment = "d3.js library, http://d3js.org"),
person("Mike", "Bostock", role = c("ctb", "cph"), comment = "d3.js library, https://d3js.org"),
person(family = "RStudio", role = c("cph"))
)
Description: Suite of tools for using 'D3', a library for producing dynamic, interactive data
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# r2d3 0.2.6

- Fix bug that would cause multiple dependencies for css or js to silently fail.

# r2d3 0.2.5

- Support for D3 v6 (@dkjoluju, #85).
Expand Down Expand Up @@ -28,4 +32,4 @@
- Publish D3 visualizations to the web
- Incorporate D3 scripts into R Markdown reports, presentations, and dashboards
- Create interacive D3 applications with Shiny
- Distribute D3 based htmlwidgets in R packages
- Distribute D3 based htmlwidgets in R packages
10 changes: 7 additions & 3 deletions R/script.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ script_wrap <- function(deps, script, container) {
)
}


script_read <- function(script) {
if (
is.null(script) ||
# Make sure we can properly resolve the scripts as files. If we can't, because
# none were passed or because the script was just in-lined, then just return
# the scripts back to the caller
unresolvable_script_paths <- is.null(script) ||
length(script) == 0 ||
any(!file.exists(script))
) {

if (unresolvable_script_paths) {
return(script)
}

Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (rstudio$version < "1.2.637")
packageStartupMessage(
"r2d3 should be run under RStudio v1.2 or higher. Please update at:\n",
"https://rstudio.com/products/rstudio/download/\n"
"https://www.rstudio.com/products/rstudio/download/\n"
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ visualizations](https://d3js.org/) with R, including:
- Creating interactive D3 applications with
[Shiny](https://shiny.rstudio.com/)

- Distributing D3 based [htmlwidgets](http://www.htmlwidgets.org) in R
- Distributing D3 based [htmlwidgets](https://www.htmlwidgets.org) in R
packages

<div style="clear: both">
Expand Down Expand Up @@ -75,7 +75,7 @@ devtools::install_github("rstudio/r2d3")
```

Next, install the [preview release of RStudio
v1.2](https://rstudio.com/products/rstudio/download/) of RStudio (you
v1.2](https://www.rstudio.com/products/rstudio/download/) of RStudio (you
need this version of RStudio to take advantage of various integrated
tools for authoring D3 scripts with r2d3).

Expand All @@ -91,7 +91,7 @@ graphics programming (similar to creating custom grid graphics in R).
It’s therefore a good fit when you need highly custom visualizations
that aren’t covered by existing libraries. If on the other hand you are
looking for pre-fabricated D3 / JavaScript visualizations, check out the
packages created using [htmlwidgets](http://www.htmlwidgets.org), which
packages created using [htmlwidgets](https://www.htmlwidgets.org), which
provide a much higher level interface.

If you are completely new to D3, you may also want to check out the
Expand Down Expand Up @@ -169,7 +169,7 @@ are provided automatically are:
## D3 Preview

The [RStudio v1.2 preview
release](https://rstudio.com/products/rstudio/download/) of RStudio
release](https://www.rstudio.com/products/rstudio/download/) of RStudio
includes support for previewing D3 scripts as you write them. To try
this out, create a D3 script using the new file menu:

Expand Down
6 changes: 6 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## R CMD check results

0 errors | 0 warnings | 1 note

This fixes the bug caused by the lines `is.null(script) || length(script) == 0 || !file.exists(script)` in the `script_read()` function within `script.R`. The
potentially length > 1 vector of booleans is now reduced to a single with `any()`.
4 changes: 2 additions & 2 deletions vignettes/data_conversion.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(eval = FALSE)

## Default conversion

R objects provided as `data` for D3 visualizations are converted to JSON using the [jsonlite::toJSON()](https://www.rdocumentation.org/packages/jsonlite/versions/1.5/topics/toJSON%2C%20fromJSON) function, and use the same default serialization behavior as [Shiny](https://shiny.rstudio.com) and [htmlwidgets](http://www.htmlwidgets.org/develop_advanced.html#custom-json-serializer).
R objects provided as `data` for D3 visualizations are converted to JSON using the [jsonlite::toJSON()](https://www.rdocumentation.org/packages/jsonlite/versions/1.5/topics/toJSON%2C%20fromJSON) function, and use the same default serialization behavior as [Shiny](https://shiny.rstudio.com) and [htmlwidgets](https://www.htmlwidgets.org/develop_advanced.html#custom-json-serializer).

This corresponds to the following call to `jsonlite::toJSON()`:

Expand All @@ -28,7 +28,7 @@ jsonlite::toJSON(

#### Data frames

Data frames are serialized with a columns orientation as that is a more compact over the wire representation than rows orientation. When the data frame gets to the client **r2d3** calls the [HTMLWidgets.dataframeToD3()](http://www.htmlwidgets.org/develop_advanced.html#htmlwidgets.dataframetod3) method to transform the data to a D3-friendly rows orientation.
Data frames are serialized with a columns orientation as that is a more compact over the wire representation than rows orientation. When the data frame gets to the client **r2d3** calls the [HTMLWidgets.dataframeToD3()](https://www.htmlwidgets.org/develop_advanced.html#htmlwidgets.dataframetod3) method to transform the data to a D3-friendly rows orientation.

Here is an example of the JSON columns-based representation of an R data frame:

Expand Down
4 changes: 2 additions & 2 deletions vignettes/development_and_debugging.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ This article describes recommend workflow for developing D3 visualizations, incl

2) Using browser debugging tools to pinpoint errors in your code.

Note that the development tools described above are only fully supported within the [RStudio v1.2 preview release](https://rstudio.com/products/rstudio/download/) (as opposed to the current stable release) so you should download the daily build before trying these features out.
Note that the development tools described above are only fully supported within the [RStudio v1.2 preview release](https://www.rstudio.com/products/rstudio/download/) (as opposed to the current stable release) so you should download the daily build before trying these features out.

## RStudio Preview

The [RStudio v1.2 preview release](https://rstudio.com/products/rstudio/download/) includes support for previewing D3 scripts as you write them. To try this out, create a D3 script using the new file menu:
The [RStudio v1.2 preview release](https://www.rstudio.com/products/rstudio/download/) includes support for previewing D3 scripts as you write them. To try this out, create a D3 script using the new file menu:

<img src="images/new_script.png" class="screenshot" width=600/>

Expand Down
2 changes: 1 addition & 1 deletion vignettes/gallery/morley/box.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {

// Inspired by http://informationandvisualization.de/blog/box-plot
// Inspired by https://informationandvisualization.de/blog/box-plot
d3.box = function() {
var width = 1,
height = 1,
Expand Down
4 changes: 2 additions & 2 deletions vignettes/gallery/stackedbars/stackedbars.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// !preview r2d3 d3_version = 4

// Based on: http://bl.ocks.org/mbostock/3943967
// Based on: https://bl.ocks.org/mbostock/3943967

var n = 4, // The number of series.
m = 58; // The number of values per series.
Expand Down Expand Up @@ -102,7 +102,7 @@ function transitionStacked() {

// Returns an array of m psuedorandom, smoothly-varying non-negative numbers.
// Inspired by Lee Byron’s test data generator.
// http://leebyron.com/streamgraph/
// https://leebyron.com/streamgraph/
function bumps(m) {
var values = [], i, j, w, x, y, z;

Expand Down
4 changes: 2 additions & 2 deletions vignettes/publishing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ Note that in order to use the `d3` engine you need to add `library(r2d3)` to the

### flexdashboard

The [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard) R Markdown format is a great way to publish a set of related D3 visualizations. You can use flexdashbaord to combine D3 visualizations with narrative, data tables, other [htmlwidgets](http://www.htmlwidgets.org), and static R plots:
The [flexdashboard](https://pkgs.rstudio.com/flexdashboard/) R Markdown format is a great way to publish a set of related D3 visualizations. You can use flexdashbaord to combine D3 visualizations with narrative, data tables, other [htmlwidgets](https://www.htmlwidgets.org), and static R plots:

<img src="images/flexdashboard.png" class="illustration" width=600/>

Check out the [flexdashboard online documentation](https://rmarkdown.rstudio.com/flexdashboard) for additional details.
Check out the [flexdashboard online documentation](https://pkgs.rstudio.com/flexdashboard/) for additional details.


## Shiny applications
Expand Down
2 changes: 1 addition & 1 deletion vignettes/shiny.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ In the D3 script, we called `Shiny.setInputValued()` with an input named `bar_cl

The `output$selected()` function uses `renderText()` to display the cosine of the bar that was clicked on. The call to `input$bar_clicked` is used inside `renderText()` to execute the `cos()` calculation.

The default value of `input$bar_clicked` will be `NULL` at the startup of the app. In this state you won't want to perform any calculation (as it would result in an error) or display any output. Shiny's `req()` function can be used to prevent errors in this case `req()` stops reactivity if the value of the variable passed as an argument is not valid, read more about this function in Shiny's official site: [Check for required values](http://shiny.rstudio.com/reference/shiny/latest/req.html)
The default value of `input$bar_clicked` will be `NULL` at the startup of the app. In this state you won't want to perform any calculation (as it would result in an error) or display any output. Shiny's `req()` function can be used to prevent errors in this case `req()` stops reactivity if the value of the variable passed as an argument is not valid, read more about this function in Shiny's official site: [Check for required values](https://shiny.rstudio.com/reference/shiny/latest/req.html)

Here is the Shiny application in action:

Expand Down
4 changes: 2 additions & 2 deletions vignettes/visualization_options.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ When you render a D3 visualization, **r2d3** creates an R [htmlwidget](http://ww

2) Conforming to the currently active `fig.width` and `fig.height` chunk options within [R Markdown](https://rmarkdown.rstudio.com) documents.

3) Filling available space when used in a [Shiny application](https://shiny.rstudio.com) or a [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard).
3) Filling available space when used in a [Shiny application](https://shiny.rstudio.com) or a [flexdashboard](https://pkgs.rstudio.com/flexdashboard/).

In order to take advantage of this dynamic sizing behavior, your should ensure that your D3 visualization uses the `width` and `height` variables that are provided automatically. Note the use of `height` in the computation of `barHeight` and `width` in the call to `.attr()` in this example:

Expand Down Expand Up @@ -175,5 +175,5 @@ The `viewer` argument to the `r2d3()` function enables you to customize how D3 v

The "external" option is useful if your visualization requires more space than an RStudio pane affords. The "browser" option is useful if you need access to browser debugging tools during development.

Note that the `viewer` options described above are only fully supported within the [preview release of RStudio v1.2](https://rstudio.com/products/rstudio/download/) (as opposed to the current stable release).
Note that the `viewer` options described above are only fully supported within the [preview release of RStudio v1.2](https://www.rstudio.com/products/rstudio/download/) (as opposed to the current stable release).