Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
smpa01
Super User
Super User

Sharing variables between languages

Does anyone know how can I pass on a python variable to a js execution from one cell to another.

 

E.g.

smpa01_0-1723922595774.png

 

Also, how can I pass on the the result of js execution to a succeeding python cell. I don't mind if I need to convert it to a string before sharing from cell to cell. I can always convert back a string to float pre process if I need to.

 

Thank you in advance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
3 REPLIES 3
Anonymous
Not applicable

Hi @smpa01 

 

It seems javascript is not an official supported language in the code cell of Fabric notebook. And it's a challenge to pass a variable between Pyspark code cell and JS code cell.    

vjingzhanmsft_1-1724403087042.png

 

As an alternative, you may use Python to execute the JS code. Some python libraries provide the functionality to call Javascript from Python. This makes it easier to pass variables. 

 

I create a sample as below by using js2py. Create a function in JS, then call this function by Python. We can pass python variables to the JS function and get the result into another python variable. 

vjingzhanmsft_0-1724402995130.png

import js2py

get_pow = js2py.eval_js('function get_pow(a, b) {return Math.pow(a, b)}')
result = get_pow(10, 3)
print(result)

 

References:

Call Javascript from python - Stack Overflow

GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator & JavaScript interpreter written in 1...

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

I am not keen on running js in isolation in notebook cell, rather I want to be able to share variables to js from other languages so that I can ask js to do things it is best at and then pass on bak those to succedding cells to a different langugae. That is the big picture.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
frithjof_v
Super User
Super User

I have no experience with, and have not heard about, using %%javascript before.

 

Perhaps you could use a Lakehouse file to read/write from?

 

When switching between spark.sql() (PySpark) and %%sql (SparkSQL) cells I have been able to use temporary views.

Helpful resources

Announcements
September Fabric Update Carousel

Fabric Monthly Update - September 2025

Check out the September 2025 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors