okld / streamlit-elements Goto Github PK
View Code? Open in Web Editor NEWCreate a draggable and resizable dashboard in Streamlit, featuring Material UI widgets, Monaco editor (Visual Studio Code), Nivo charts, and more!
License: MIT License
Create a draggable and resizable dashboard in Streamlit, featuring Material UI widgets, Monaco editor (Visual Studio Code), Nivo charts, and more!
License: MIT License
I have one or more mui elements with an onmouseover, or onclick event handler. When they are being activated closely together time-wise, ie: the mouse swipe over several onmouseover objects, or repeatedly click a mui.typography with onclick listener, it throws error and crashes streamlit. It is possibly due to streamlit being reloading, and the targets are being regenerated. A global debounce mechanism for all mouse and touch events might be a solution.
Please guide me to a more correct place to ask this question, if here is not the right one.
I have a page designed with streamlit-elements, and I want to add a plot to it. I know how to create this plot with matplotlib
, and if I used just pure streamlit, I would just call streamlit.write(figure)
to display it. However, this way the image renders above all streamlit_elements, and I want it instead to land within the specific streamlit_elements.mui.Card
element.
How can I achieve this, and does it make sense at all?
Hi, I'm trying to install as a git submodule using the following commands:
git submodule add https://github.com/okld/streamlit-elements.git
cd streamlit-elements
pip install .
unfortunately i get the following error:
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [71 lines of output]
Traceback (most recent call last):
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\expand.py", line 81, in __getattr__
return next(
^^^^^
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\expand.py", line 191, in read_attr
return getattr(StaticModule(module_name, spec), attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\expand.py", line 87, in __getattr__
raise AttributeError(f"{self.name} has no attribute {attr}") from e
AttributeError: streamlit_elements has no attribute __version__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\SVL\Desktop\ua\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "c:\Users\SVL\Desktop\ua\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\SVL\Desktop\ua\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 149, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\build_meta.py", line 380, in prepare_metadata_for_build_wheel
self.run_setup()
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\build_meta.py", line 488, in run_setup
self).run_setup(setup_script=setup_script)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
exec(code, locals())
File "<string>", line 3, in <module>
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\__init__.py", line 107, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 159, in setup
dist.parse_config_files()
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\dist.py", line 904, in parse_config_files
setupcfg.parse_configuration(
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 189, in parse_configuration
meta.parse()
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 500, in parse
section_parser_method(section_options)
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 475, in parse_section
self[name] = value
~~~~^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 293, in __setitem__
parsed = self.parsers.get(option_name, lambda x: x)(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 606, in _parse_version
return expand.version(self._parse_attr(value, self.package_dir, self.root_dir))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\setupcfg.py", line 417, in _parse_attr
return expand.read_attr(attr_desc, package_dir, root_dir)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\expand.py", line 194, in read_attr
module = _load_spec(spec, module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SVL\AppData\Local\Temp\pip-build-env-fin4703t\overlay\Lib\site-packages\setuptools\config\expand.py", line 214, in _load_spec
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\SVL\Desktop\ua\streamlit-elements\streamlit_elements\__init__.py", line 1, in <module>
from streamlit_elements.core.frame import new_frame as _new_frame
File "C:\Users\SVL\Desktop\ua\streamlit-elements\streamlit_elements\core\frame.py", line 3, in <module>
from streamlit import session_state
ModuleNotFoundError: No module named 'streamlit'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
I've installed streamlit in a venv and activated the venv using vscode on widows before trying to install the repository - I'm probably doing something daft!
Thanks!
Hi, I just started with this library today and it's amazing!
This is the code that I'm using in a custom card to start strategies in Hummingbot:
with mui.Select(label="Scripts", onChange=lazy(lambda x: self.set_strategy(x, bot_name))):
for script in scripts:
mui.MenuItem(script, value=script)
and this is the method set_strategy:
@staticmethod
def set_strategy(event, bot_name):
st.session_state.active_bots[bot_name]["selected_strategy"] = event.target.value
When I press another button that triggers the execution I'm receiving this error:
File "/Users/dardonacci/Documents/work/dashboard/ui_components/bot_performance_card.py", line 66, in <lambda>
with mui.Select(label="Scripts", onChange=lazy(lambda x: self.set_strategy(x, bot_name))):
File "/Users/dardonacci/Documents/work/dashboard/ui_components/bot_performance_card.py", line 15, in set_strategy
st.session_state.active_bots[bot_name]["selected_strategy"] = event.target.value
File "/Users/dardonacci/anaconda3/envs/dashboard/lib/python3.9/site-packages/streamlit_elements/core/callback.py", line 138, in __getattr__
return self.__getitem__(value)
I also inspected the event that arrives in the function and is the dict --> {"isTrusted":false}
I don't know react so probably I'm missing something in how to use mui.Select, any help is welcome!
Is it possible to use Plotly Charts in the Dashboard feature?
Really appreciate this component, I am having to rely on it as native streamlit does not allow for nesting of columns for a particular app feature I am building.
After having employed the Autocomplete
mui widget, I get an error suggesting ElementsFrontendError: In elements frame 'streamlit_elements.core.frame.elements_frame.workboard': we is not a function
when in fact there is no we
in my code. I looked into my streamlit session_state key values and also found no we
there as the error callbacks seem to point to session state. What seems to be the problem here? Would kindly appreciate some help resolving this issue.
Really love this component as it gives a pythonic feel to the typescript/react coding and expands the capabilities of streamlit.
I trying to implement star rating in streamlit app, but mui.Rating is throwing errors, I'm not able to define handle_change function and hence I'm getting errors, is it possible to implement that?
Thank you
Hi okld and hi everyone, I hope this project still lives because it's very helpful to render nice Streamlit apps.
I'm working with Autocomplete component from MUI but I'm struggling making it works. The issue here is that mui.Autocomplete object needs a renderInput prop (it should be a lambda function returning another component such as TextField). Here is how I proceed to try making it works :
with elements("some-name"):
options=[{"label": labels[i], "id": i} for i in range(len(labels))] # labels is defined as a list of strings
autocomplete = mui.Autocomplete(options=options, renderInput=lambda params: mui.TextField(params, label="Some label"))
The problem here is that it throws an ElementsFrameError cause mui.TextField is out of an with elements("id") statement.
I tried some variations such as :
My question is : How to make mui.Autocomplete work with streamlit-elements module ?
NB : Moreover, I was wondering if we could have some tutorials on how to make Date Pickers work for example. Thank you very much for your help and consideration
Victor
getattr should raise a AttributeError when value is not found, not KeyError, which is raised when getitem fails. New function should look like
class ElementsCallbackData(dict):
slots = ()
def __getattr__(self, value):
try:
return self.__getitem__(value)
except:
raise AttributeError
Hey Everyone,
I tried running the following code (taken from the streamlit-gallery repo), but I cannot see any table (only the arrows for switching pages are shown). wondering what am I missing here:
import streamlit as st
from streamlit_elements import mui, elements
DEFAULT_COLUMNS = [
{ "field": 'id', "headerName": 'ID', "width": 90 },
{ "field": 'firstName', "headerName": 'First name', "width": 150, "editable": True, },
{ "field": 'lastName', "headerName": 'Last name', "width": 150, "editable": True, },
{ "field": 'age', "headerName": 'Age', "type": 'number', "width": 110, "editable": True, },
]
DEFAULT_ROWS = [
{ "id": 1, "lastName": 'Snow', "firstName": 'Jon', "age": 35 },
{ "id": 2, "lastName": 'Lannister', "firstName": 'Cersei', "age": 42 },
{ "id": 3, "lastName": 'Lannister', "firstName": 'Jaime', "age": 45 },
{ "id": 4, "lastName": 'Stark', "firstName": 'Arya', "age": 16 },
{ "id": 5, "lastName": 'Targaryen', "firstName": 'Daenerys', "age": None },
{ "id": 6, "lastName": 'Melisandre', "firstName": None, "age": 150 },
{ "id": 7, "lastName": 'Clifford', "firstName": 'Ferrara', "age": 44 },
{ "id": 8, "lastName": 'Frances', "firstName": 'Rossini', "age": 36 },
{ "id": 9, "lastName": 'Roxie', "firstName": 'Harvey', "age": 65 },
]
with elements("new_element"):
mui.DataGrid(
columns=DEFAULT_COLUMNS,
rows = DEFAULT_ROWS,
pageSize=5,
checkboxSelection=True,
)
I managed to use mui.DataGrid to show a table. Assuming I have the columns dictionary, what do I need to add so that a specific column will be a link?
TIA!
Thank you for creating such an amazing component, it is exactly what I had been hoping for. I have been playing around with it a bit and having difficulty accessing values from the event callbacks for the RadioGroup Below is my code for the radio group:
` with elements('RadioGroup'):
if "radio_value" not in st.session_state:
st.session_state.radio_value = None
if st.session_state.radio_value is not None:
selection = st.session_state.radio_value
else:
selection = []
with mui.FormControl:
mui.Typography('Radio Test')
mui.Typography(f'Event Valuue: {selection}')
with mui.RadioGroup(name = 'RadioTest',defaultValue = 'Never', onChange = sync('radio_value')):
mui.FormControlLabel(value='Never', control = mui.Radio(), label = 'Never')
mui.FormControlLabel(value='Always', control = mui.Radio(), label = 'Always')`
When I do this, the "radio_value" attribute in session_state is equal to a dictionary with the following values:
{'type': 'change', 'nativeEvent': {'isTrusted': True}, 'target': {'checked': True}, 'eventPhase': 3, 'bubbles': True, 'cancelable': True, 'timeStamp': 3176.4000000059605, 'defaultPrevented': False, 'isTrusted': True}
From this I would have expected to have gotten target.value, but there is only target.checked, which in this case is always true since something is checked.
It is highly possible this is an error in my code but curious if you had any input or if this is just one of the components that still has problems as you described in the Readme.
Hey @okld ,
can i somehow pass args to a callback function?
def handle_onclick(event, args):
passed_arg = args[0]
mui.button("clickme", onClick=handle_onclick, args=("blub"))
Why args at all? I want to pass some information to the button as i have a button-list.
So i need somehow to save some information, what button was clicked.
Is it possible to use mui.DataGrid? I couldn't figure out how to define the rows and columns in Python.
My naïve attempt:
columns = [
{"field": "id", "headerName": "ID", "width": 70},
{"field": "firstName", "headerName": "First name", "width": 130},
{"field": "lastName", "headerName": "Last name", "width": 130},
{
"field": "age",
"headerName": "Age",
"type": "number",
" width": 90,
},
]
rows = [
{"id": 1, "lastName": "Snow", "firstName": "Jon", "age": 35},
{"id": 2, "lastName": "Lannister", "firstName": "Cersei", "age": 42},
{"id": 3, "lastName": "Lannister", "firstName": "Jaime", "age": 45},
]
mui.DataGrid(columns=columns, rows=rows, pageSize=5, checkboxSelection=True)
I see in documentation that Nivo Sunburst supports custom layers via it's layers
property. However, I do not understand what can be provided as a custom layer. I see that it may be a function, so I made one. However, attempting to return a string from it or an object, results in exception.
def custom_layer(obj):
nodes = obj['nodes']
centerX = obj['centerX']
centerY = obj['centerY']
print(f"centerX: {centerX}, centerY: {centerY}")
return html.div("custom_layer")
nivo.Sunburst(data=DATA, enableArcLabels=True, arcLabel="id", layers=["arcs", 'arcLabels', custom_layer])
It throws an non-identifiable exception since react is minified.
When I use image component like html.Img( src = "/static/xxx.jpg"), the root location is the module's path "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/streamlit_elements/frontend/build/". So I can't load images in my own folders.
Same issus happens when I use src = "data:image/png;base64,XXXXX", which should use the bytes data.
Thanks for your job on this cool package!
Hi @okld,
Thanks for your contribution to sharing this awesome Streamlit component!
I am wondering would you like to share the codes of the demo on share.streamlit.io?
I wanna try the function of switching the light-dark theme for each element and the feature of checking out different items in one element.
Thank you in advance!
Best regards,
Chieh
onChange event is not working after Streamlit 1.34 release.
I cannot resize the height of the grid (only) from the dashboard.
This is an awesome library, and has a good potential to change the way streamlit apps are created. It would've been fabulous if there's more documentation on it. For instance, how to create dropdown menu, how to use clickawaylistener etc.
I'm open to collaborating if anyone's interested. Thanks!
Hi,
following on this topic. Is this repo still maintained?
thanks
When streamlit app is in dark mode, the tooltip of the nivo Pie chart displays white text on white tooltip background instead of black (or any discernible color) on white or white text on dark background.
st.markdown()
but it doesn't work in case of an iframe
, which is the case for streamlit-elements nivo pie chart, its not possible to reach the element by class or id to affect the text color.how to use mui.CardMedia for local images?
2024-05-02 12:05:32.674 Uncaught app exception
Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 584, in _run_script
exec(code, module.__dict__)
File "/workspaces/streamlit-gallery/streamlit_app.py", line 3, in <module>
from streamlit_gallery import apps, components
File "/workspaces/streamlit-gallery/streamlit_gallery/components/__init__.py", line 5, in <module>
from .pandas_profiling.streamlit_app import main as pandas_profiling
File "/workspaces/streamlit-gallery/streamlit_gallery/components/pandas_profiling/streamlit_app.py", line 2, in <module>
import pandas_profiling
File "/home/vscode/.local/lib/python3.11/site-packages/pandas_profiling/__init__.py", line 6, in <module>
from pandas_profiling.controller import pandas_decorator
File "/home/vscode/.local/lib/python3.11/site-packages/pandas_profiling/controller/pandas_decorator.py", line 4, in <module>
from pandas_profiling.profile_report import ProfileReport
File "/home/vscode/.local/lib/python3.11/site-packages/pandas_profiling/profile_report.py", line 13, in <module>
from pandas_profiling.config import Config, Settings
File "/home/vscode/.local/lib/python3.11/site-packages/pandas_profiling/config.py", line 5, in <module>
from pydantic import BaseModel, BaseSettings, Field
File "/home/vscode/.local/lib/python3.11/site-packages/pydantic/__init__.py", line 386, in __getattr__
return _getattr_migration(attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/pydantic/_migration.py", line 296, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.7/migration/#basesettings-has-moved-to-pydantic-settings for more details.
For further information visit https://errors.pydantic.dev/2.7/u/import-error
Hi, thanks for the awesome package! I just wondered if it would work to redirect the paths for the Date and Time pickers as they don't exist in lab now?
https://mui.com/blog/lab-date-pickers-to-mui-x/
as per the following:?
e.g. change in Lab.tsx
DatePicker: dynamic(() => import("@mui/lab/DatePicker"), { loading: ElementsLoading, ssr: false }),
to
DatePicker: dynamic(() => import("@mui/x-date-pickers/DatePicker"), { loading: ElementsLoading, ssr: false }),
If not, is there another way?
This component could use all the componet from MUI, is there any document about how to use them in streamlit?
Hi everyone, hi @okld,
I was trying to use some tooltips with the mui.Tooltip element, but if I do, it throws an ElementsFrontendError:
ElementsFrontendError: In elements frame 'streamlit_elements.core.frame.elements_frame.tooltip_test': Cannot read properties of undefined (reading 'addEventListener')
I have used the following snippet:
with elements("tooltip_test"):
with mui.Tooltip(title="Tooltip"):
mui.Typography(
"Tooltip"
)
Is there something I missed?
Tooltip shows up as expected.
Usage of mui.Tooltip results in an ElementsFrontendError.
ElementsFrontendError: In elements frame 'streamlit_elements.core.frame.elements_frame.tooltip_test': Cannot read properties of undefined (reading 'addEventListener')
with elements("tooltip_test"):
with mui.Tooltip(title="Tooltip"):
mui.Typography(
"Tooltip"
)
Is it possible to create mui.Tabs? I noticed that the option is available, but TabPanel is missing…
Is there a way to create tabs with mui in streamlit?
Thank you very much for this great package!
Kind Regards,
I'm using streamlit-gallery (https://github.com/okld/streamlit-gallery) based on streamlit-elements and I successfully recreated the nivo radar and pie chart plots as shown in the draggable UI demo (which is fantastic) and I also expanded the functionality to include bump, areabump and chord plots.
However, I cannot get nivo/boxplot to work, presumably because boxplots were added rather recently to nivo (plouc/nivo#849 (comment)).
What are necessary steps that I need to take to make nivo/boxplot useable in the draggable UI, just like radar and pie charts?
python: python 3.10
OS: Win10
Related pip packages:
streamlit-elements 0.1.0
streamlit 1.9.0
It would be great to have the possibility to use DataGridPro (after buying a license of course)
I added a download button on Pie chart
I'm interested in how to write a function that downloads CSV files when this button is clicked
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.