5

I would like to pass a simple variable to an html cell on Jupyter:

cell 1:

a=5

cell 2:

%%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.

1 Answer 1

5

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.