Hello there!
I have applied your suggested solution to modify as custom components it in callback.py but still it has no effect when i am trying to use onChange event in mui.checkBox().
do i also need to do something after modifying the source code?
Hi Nina, Thanks for your valuable response
But the solution you recommended. i do not find that function written in callback.py.
i see def __patch_register_widget(register_widget) function .
Do i need to add this def patch_modules_streamlit_elements as new function in callback.py or create a new file for it?
could you also please tell me in which older version of streamlit ,1.32 or 1.33 does this call back functions were actually working? i am using streamlit 1.39.0 version
Normally, you donât need to manage the âcallback. pyâ file. After installing the âstreamlit elementsâ package, you just need to runâ streamlit run text. py âdirectly in the newly createdâ text. py 'file.
It should be noted that after running, be sure to restart your own streamlit application.
def patch_modules_streamlit_elements(file: str, old_line: str, new_line: str):
import streamlit_elements
import os
relative_file_path = "core/callback.py"
library_root = list(streamlit_elements.__path__)[0]
file_path = os.path.join(library_root, relative_file_path)
with open(file_path, "r") as file:
lines = file.readlines()
is_changed = False
for index, line in enumerate(lines):
if old_line in line:
print(f"Replacing line {index + 1} in {file_path}")
lines[index] = line.replace(old_line, new_line)
is_changed = True
if is_changed:
with open(file_path, "w") as file:
file.writelines(lines)
import importlib
importlib.reload(streamlit_elements)
return True
def patch_streamlit_elements():
# fix 1.34.0
patch_modules_streamlit_elements(
"core/callback.py",
"from streamlit.components.v1 import components",
"from streamlit.components.v1 import custom_component as components\n",
)
#fix 1.40.0
patch_modules_streamlit_elements(
"core/callback.py",
' user_key = kwargs.get("user_key", None)\n',
"""
try:
user_key = None
new_callback_data = kwargs[
"ctx"
].session_state._state._new_session_state.get(
"streamlit_elements.core.frame.elements_frame", None
)
if new_callback_data is not None:
user_key = new_callback_data._key
except:
user_key = None
""".rstrip()
+ "\n",
)
if __name__ == "__main__":
patch_streamlit_elements()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.