Hello,
I am trying to implement a streamlit component with a viewer already prebuilt seemingly from webpack
more specifically glvis-js for viewing 3d meshes for finite element analysis done with mfem. I am by no means a coder in javascript or react, but just trying to include a viewer to streamlit.
Is there a way or advice on how to integrate this into a component through React or Typescript? Without missing definitions (see screenshot below). I am aware that I need to create some object for some definitions to exist, but more about the 'X' is not defined
Or is there a way to include a javascript source file into the component file tree that can be referenced by __init__.py
. This is because there is no hosting of the javascript file on any CDN, an example is in the code snippet below,
# __init__.py
import streamlit.components.v1 as components
...
def my_component(var1, var2, key=None):
component.html("<script src='<SCRIPT_LOCAL_TO_COMPONENT>'>...</script>")
This would be the simplest way to get the application working, or is there a way to use the provided index.js
wrapper for glvis.js
into the frontend component from glvis-js
that may not conflict with the internals? Here is the
initial conversation I started.
Any advice or direction would be greatly appreciated.
Cheers,
Debug info
- Streamlit version: 0.81.1
- Python version: 3.7.10
- OS version: macOS High Sierra
- Browser version: Firefox 88.0
Screenshot
From github from Fanilo
Since this is more of a Streamlit usage question, you will get a bit more answers on the forum, especially if it’s about creating new components/visualizers in Streamlit, we’re always on the lookout for those!
Now regarding your question (we can go into detail on the forum ), I haven’t tested this is still intuition but if you’re trying the
def my_component(var1, var2, key=None):
component.html("<script src='<SCRIPT_LOCAL_TO_COMPONENT>'>...</script>")
method, my guess is
SCRIPT_LOCAL_TO_COMPONENT
will need to be in Streamlit’s static folder (which you can find withpython -c "import streamlit as st; print(st.__path__)
, check out this answer for a bit more detail).
Another way would be to read the entire
glviz.js
in Python and then pasting the content inside the<script>
tag in thecomponents.html
call.
PS. Thanks Fanilo