okld / streamlit-ace

Ace editor component for Streamlit.
https://share.streamlit.io/okld/streamlit-gallery/main?p=ace-editor
MIT License
254 stars 38 forks source link

Is there a way to change the content of value parameter #9

Closed cwerner closed 3 years ago

cwerner commented 3 years ago

Hi.

I want to populate the ACE editor with the content from a file before editing. This works, but I want the user to be able to pick another files' content on the fly and then the ACE editors value should be changed. But this does not seem to work...

Am I missing something here?

Would you have any idea how this could be achieved?

Cheers, C

cwerner commented 3 years ago

Ok, answering my own issue (maybe)... 😉

I achieved the effect I wanted by making sure the ace-editor key argument changes with the different policy selections from the selectbox that I want to show and edit...

    policy = st.selectbox('Existing policies', policy_files)
    policy_json = json.load(policy.open())
    file_content = json.dumps(policy_json, indent=4, sort_keys=True)

    content = st_ace(
        language="json",
        font_size=8,
        height=250,
        value=file_content,
        key=f"ace-editor-{policy_json}",
        auto_update=False,
    )
okld commented 3 years ago

Hello @cwerner, you found the way! This is how you would refresh regular streamlit widgets as well.