I would like to include the open source molecule editor JSME into a Streamlit app.
I’ve found out that there is already a React component: https://github.com/DouglasConnect/jsme-react
However, I’m not getting it to display in my app.
I used the component template and added something like:
import { Jsme } from 'jsme-react'
class MyComponent extends StreamlitComponentBase {
public render = (): ReactNode => {
return (
<div>
<h1>Hello World</h1>
<Jsme height="500px" width="800px" />
</div>
)
}
}
export default withStreamlitConnection(MyComponent);
The “Hello World” shows up but not the rest.
I am very new to React, JS, etc.
Thanks for your patience. I took a look at your example, and it unfortunately falls into a bucket of component types that would not work at the moment. Essentially, jsme-react is making a request for the main library jsme. We originally designed our application with security in mind and blocked all requests to outside sources (Through Cross-Origin Resource Sharing or CORS).
JSME is weird because it’s not an importable library like most other libraries are. The workaround today would be to download the JSME library (not the jsme-react library) and load the library locally (we would need to test that, but if more requests are made outside, it would not work). Sorry if that seems like a lot. It might work better using the template-reactless setup.
The good news is we studied how to securely remove this block measure, and we found a solution that we hope to fix soon, hopefully by the end of the month.
Sorry, I could not give you a better answer, but I’m excited to get this fix in as it would open up more possibilities. Looking forward to seeing the JSME editor then.
Many thanks for following up on this.
Sad, to hear that it won’t work at the moment, but I’m confident that you guys will fix it in the future.
Meanwhile I’ll have a look at the reactless template. Unfortunately I didn’t find many examples for that so far.
Having JSME (or something similar) working in Streamlit would be a valuable tool for the scientific community, since it is quite popular in cheminformatics web-apps.
@LeChuck If I have some time, I can see if I can start making one for you to finish. I can’t guarantee it, but doing a ridiculously quick proof of concept should probably take an hour or two to see if it’s successful.
Many thanks for the info of the new version and the link to @iwatobipen’s blog. And sorry for the late reply - I was on vacation.
This is really awesome!
I downloaded the example from the link and it works fine. However, it only works in development mode (when I run “npm start”). When I build with “npm run build” or “yarn build” the build process terminates fine, but the built component doesn’t work in the app.
Any ideas what could be the reason? Building other components worked for me so far…
Also, when start the component with an empty SMILES (smiles="") the component doesn’t show up at all. But this might also be an issue from JSME.
Dear @LeChuck ,
I’m @iwatobipen who is author of the blog. Nice to meet you.
Thanks for reading my blog.
And could you please share error message when you run my code? I would like to try to fix the issue.
Thanks.
The frontend was compiled properly and the path is also correct.
Does it work for you?
I managed to fix the second issue: you have to completely remove the smiles=“…” part from the App.js in order to start with an empty editor. My mistake…
This is that part of the code from @iwatobipen I used:
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import SimilarityMaps
from io import BytesIO
from functools import partial
from PIL import Image
from rdkit.Chem.Draw import rdDepictor
rdDepictor.SetPreferCoordGen(True)
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.