-
Notifications
You must be signed in to change notification settings - Fork 71
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
Javascript interop should provide element for js callbacks #223
Comments
Have you seen the example in the feature notebook? It has an example of interop with D3 where it creates a new div and manipulates that. That seems a controlled way of interacting with JavaScript libraries. |
This approach only works with d3 because it registers itself as a global dependency, Modern libraries are using |
I'm a bit confused what you're after. Dependency resolution is different from having a magic Separately it's not clear if the sort of magic IPython provide provides is a good idea. It would be risky for us to introduce as previously |
I think what I wanted was something like this: // helper or util function
let runJavascript (js:string) =
let id = System.Guid.NewGuid().ToString()
sprintf """
<div id='cell-%s'></div>
<script type='text/javascript'>
var element = document.querySelector('#cell-%s');
(function() {
%s
})();
</script>""" id id js
|> Util.Html |> Display actual code in a cell """
var graph = new Rickshaw.Graph( {
element: element,
width: 300,
height: 200,
series: [{
color: "steelblue",
data: [
{ x: 0, y: 40 },
{ x: 1, y: 49 },
{ x: 2, y: 38 },
{ x: 3, y: 30 },
{ x: 4, y: 32 } ]
}]
});
graph.render();
""" |> runJavascript so it's just a way of running js code without bothering with fake html creation all the time. I will close this issue since this helper I've written is enough for me |
Great, glad you found a solution. JavaScript/Jupyter interop is very powerful but a bit messy, not sure the best set of options to provide, but that might make sense for some people. |
I've been trying to implement something like this https://gist.github.com/fabriziopandini/7e8efdd7063a518a2d2d#file-chartjs-ipython-py-L30. IPython provides
element
in JS callback which is an output cell. Which in turn allows better customization and improved workflow with some JS librariesBrowsing through issues I've found #126 to be very close to what I'd like to achieve.
The text was updated successfully, but these errors were encountered: