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

Using crosstalk with scatterD3 in a standalone R Markdown HTML Report #95

Open
vinwol opened this issue Dec 22, 2022 · 6 comments
Open

Comments

@vinwol
Copy link

vinwol commented Dec 22, 2022

Is it possible to use crosstalk with scatterD3 in a standalone R Markdown HTML Report?

Running the following code works fine as expected:

library(scatterD3)
scatterD3::scatterD3(data=iris,
x=Sepal.Width,
y=Sepal.Length,
col_var=Species)

Trying to use this example in an R Markdown HTML Report like this:

library(crosstalk)
library(scatterD3)
library(d3scatter)
df <- iris
df$helper_select_all <- T
shared_data <- SharedData$new(df)
crosstalk::filter_select("flower", "Select a flower", shared_data, ~Species, multiple = FALSE)
d3scatter::d3scatter(data=shared_data, x=~Sepal.Width, y=~Sepal.Length, color=~Species)
scatterD3::scatterD3(data=shared_data, x=~Sepal.Width, y=~Sepal.Length, col_var=~Species)

throws this error:
Error in data[, deparse(substitute(x))]: object of type 'environment' is not subsettable

The d3scatter code however works fine.

@juba
Copy link
Owner

juba commented Dec 22, 2022

Unfortunately no, scatterD3 is not crosstalk-compatible.

In fact there doesn't seem to be many crosstalk-compatible html widgets if this page is accurate :

https://rstudio.github.io/crosstalk/widgets.html

@vinwol
Copy link
Author

vinwol commented Dec 22, 2022

Could it be an option to modify the code so that the Javascript part could be used inside an R Markdown HTML document?

@juba
Copy link
Owner

juba commented Dec 26, 2022

What "JavaScript part" are you talking about exactly ?

@vinwol
Copy link
Author

vinwol commented Jan 10, 2023

I saw this example: https://stackoverflow.com/questions/56361986/zoom-function-in-rmarkdown-html-plot
Not sure the underlying JS code of scatterD3 can be adopted to work directly in the HTML document?
On a different note, could scatterD3 be included in an interactive fashion in the R Markdown HTML document, e.g. using widgetframe::frameWidget()?

@juba
Copy link
Owner

juba commented Jan 12, 2023

You are still talking about crosstalk compatibility ? Because single scatterD3 plots should work fine in HTML document, if I remember correctly.

@vinwol
Copy link
Author

vinwol commented Jan 18, 2023

My reporting involves a pipeline where many outputs are generated in a for loop. I managed to include scatterD3 in the loop in the following way: print(htmltools::tagList(scatterD3::scatterD3(...))). Recently I came across Quarto, which supports Observable and this could make it fairly easy to go with JS for the front end. Link: https://quarto.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants