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

support htmlwidgets in RCloud? #1435

Closed
gordonwoodhull opened this issue May 9, 2015 · 14 comments
Closed

support htmlwidgets in RCloud? #1435

gordonwoodhull opened this issue May 9, 2015 · 14 comments
Assignees
Milestone

Comments

@gordonwoodhull
Copy link
Contributor

We have some ad hoc support for the RStudio html ecosystem via shared.R and rcloud.shiny, but in a sense we went about this in a backwards way, watching what failed and patching it up.

Now there is htmlwidgets, which seems like it should be a nice standard for embedding HTML/JavaScript based visualizations into cells or rcloud.web applications.

I wonder how hard it would be to hook in at a deeper level and directly support this infrastructure.

@gordonwoodhull
Copy link
Contributor Author

Related links:

htmlwidgets/Zeppelin: ramnathv/htmlwidgets#146
htmlwidgets/Jupyter: ramnathv/htmlwidgets#144

@gordonwoodhull gordonwoodhull changed the title try to support htmltools and htmlwidgets? support htmlwidgets in RCloud? Jan 21, 2016
@gordonwoodhull
Copy link
Contributor Author

It looks like htmlwidgets is currently an rmarkdown-only solution, a standard which is documented on the client side but not the server side.

@gordonwoodhull
Copy link
Contributor Author

Of course, we can use rmarkdown and do support rmarkdown cells, so maybe that is a solution here.

The main complaint in the Zeppelin thread is that pandoc is slow, but I don't think that is a serious issue for us.

@gordonwoodhull
Copy link
Contributor Author

This thread is also relevant: ramnathv/htmlwidgets#86

@gaborcsardi
Copy link
Contributor

First working version: MangoTheCat@2a8d434

It uses iframes and the srcdoc attribute, which is good and bad. Good, because widgets are totally independent, no JS interference. Bad, because it does not work out of the box on IE. But there is a good polyfill: https://github.com/jugglinmike/srcdoc-polyfill

@shaneporter
Copy link
Collaborator

Don't think IE support is a requirement, is it @gordonwoodhull?

@gaborcsardi
Copy link
Contributor

@shaneporter Nevertheless, the polyfill is really simple, so why not?

@gordonwoodhull
Copy link
Contributor Author

Awesome, @gaborcsardi, please open a PR!

I am a little disappointed over iframes since they don't integrate very well, but let's start there and see if we can improve it over time. I assume that's mostly because of JS library version conflicts?

We don't currently support IE because it has "different" websocket "standards" (like pong messages), so that's not a concern right now.

@gaborcsardi
Copy link
Contributor

@gordonwoodhull Regarding iframes, it is mainly because of the simplicity. I can easily pull out a self-contained HTML page from htmlwidgets. If it is not an iframe, then I need to parse the HTML, pull out the different parts, pass them to rcloud, etc. It is not too bad, but the parsing is a lot more error-prone, and also potentially sensitive to future changes in htmlwidgets.

The current approach is quite robust I think. Plus, as you mention, we also get rid of all JS library conflicts.

IMO iframes integrate relatively well nowadays, although sizing might be an issue, that is not perfect yet. I need to read a bit about how htmlwidgets does it.

But in any case, I can try to get rid of the iframes.

@gaborcsardi
Copy link
Contributor

gaborcsardi commented May 18, 2016

@gordonwoodhull I am trying to make htmlwidgets work in mini.html. I was wondering what kind of API you would like. How about sg. like this:

library(DT)
...
    rcw.set("#mytable", htmlwidget(datatable(dataset)))
...

and htmlwidget would just return the HTML for the widget, in an iframe?

Actually, as I see it, if I implement an as.character method for htmlwidget objects, then the conversion is done automatically and this will work:

...
    rcw.set("#mytable", datatable(dataset))
...

Is this OK?

@gordonwoodhull
Copy link
Contributor Author

That looks great! Do you anticipate any ill side-effects of the as.character approach?

Another possibility to consider (depending on time) is to implement a similar behavior to images, so that the user can resize the htmlwidgets inside the notebook or dashboard. @dougmet or @shaneporter can tell you about this functionality; it's used a lot in RCAP.

This would probably require sending the data in its own ocap (see htdocs/js/session.js) when it is printed to an output context, so I think it's independent of the character-based approach.

(Presumably exporting images would not work, since htmlwidgets usually depend on the JS side to produce content.)

@gaborcsardi
Copy link
Contributor

I think as.character is safe, I don't see any problems.

Just pushed it, it works great in mini.html.

But I really need to do sg about the sizing now, it is probably even more important in mini.html. I know about the stretchy plots, let me do some research on how htmlwidgets does this, and then whether I can come up with sg reasonable.

@gaborcsardi
Copy link
Contributor

Note to myself: there is a detailed guide for html widget sizing: https://cran.r-project.org/web/packages/htmlwidgets/vignettes/develop_sizing.html

Ideally we would need to capture resizing and pass it on to the widget, but I am not sure if this will be possible with the iframes. Probably not.

If not, then I will try to get rid of the iframes tomorrow.

@gordonwoodhull
Copy link
Contributor Author

Implemented in #2016, still with iframes but they are mostly invisible.

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

No branches or pull requests

3 participants