okld/streamlit-ace

Is there a way to change the content of value parameter

cwerner opened this issue · 2 comments

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

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

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