I would like to pass a simple variable to an html cell on Jupyter:
a=5
%%html
<html>
<head>
<script type="text/javascript">
window.alert(a);
</script>
</head>
</html>
This will return an error:
Javascript error adding output!
ReferenceError: a is not defined
See your browser Javascript console for more details.
This is a hacky solution:
a=5
html_code ="""
<html>
<head>
<script type="text/javascript">
window.alert(%s);
</script>
</head>
</html>""" % a
from IPython.display import HTML
HTML(html_code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With