简体   繁体   中英

Can I call a JavaScript function on an iFrame or similar widget from Python?

I am trying to mix Python code with D3 vizualizations. Right now I have a bunch of D3 vizualizations and JavaScript functions. I have a couple different ways of embedding the D3, but what I want is to call a function that affects the vizualization AFTER I create it.

For example:

createD3Stuff()
for i in [0,1,2,3]:
    executeFunction(i)

Where createD3Stuff() generates the vizualization, and executeFunction does something on that vizualization, like creates an element with id=i.

Is this possible? How can I do it?

Background information: I am using Jupyter Notebooks, but if there is some other way to get this to work I can switch. I know how to do all the d3 and javascript stuff, it is just getting the python and javascript to interact that is giving me trouble.

Of course you can.

Just try this:

from IPython.display import HTML
HTML("<script>alert('hello world')</script>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM