Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.
Does anyone know how can I pass on a python variable to a js execution from one cell to another.
E.g.
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.
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.
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.
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
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.
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.
User | Count |
---|---|
15 | |
3 | |
3 | |
3 | |
2 |