I want to make a string that is created in Python available in Javascript.
The flow is roughly:
- a bunch of user-interactions take place in Python that result in a string (an ID); a bunch of Python libraries are involved here, and so I don’t think it’s easy to remove/rewrite this part of the process
- a user then clicks a button that makes a request to an API to download data that is linked to this string/ID
- this data can be quite large, and so I would like to download it directly to the user’s machine, rather than having it pass through the
panel
webserver
-I want to pass this ID (generated at runtime) from Python to JS and I can’t do it!
Here’s some relevant code that I am using:
import panel as pn
import param
# I get an error in the browser saying 'target is not defined'
my_js_code = """
let task_id = target.value;
console.log(task_id);
"""
class MyTable(pn.viewable.Viewer):
... # param stuff
def __init__(self, ..., **params):
self.task_id = pn.widgets.TextInput(name="Text Input", value="foo")
self.my_button = pn.widgets.Button(name='my_button')
self.my_button.js_on_click(args={"target": self.task_id}, code=my_js_code)
super().__init__(**params)
def __panel__(self):
# things to display like my_button
What do I need to change here to pass from Python to JS?
Bonus question: Is it possible (and how can I do it) to pass param
objects to JS in a similar way eg param.String()
?