question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add the ability to programatically re-run the streamlit script

See original GitHub issue

Problem

I am building a small labeling too where I read in an example, the user will select labels from a list of check boxes and click submit in order to save the labels, when they submit a field in the data for it being labeled is added so in the next read it skips that example. The problem is that the submit button will cause a rerun where the labels are collected and saved but it doesn’t cause another re-run that will cause the data to be reread (this will move the app on to the next question)

Solution

I think a solution would be a st.rerun() function that you can call to reexecute the script from the top. In my cause this would be called after my save and trigger a re-read. Basically it would do the same thing I am currently using a second Next button for but remove the need for user interaction.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:34 (21 by maintainers)

github_iconTop GitHub Comments

4reactions
SimonBiggscommented, Aug 24, 2020

The code for this has changed to:

def rerun():
    raise st.script_runner.RerunException(st.script_request_queue.RerunData(None))
3reactions
SimonBiggscommented, Jul 16, 2020

A neater fix seems to be the following:

import streamtlit as st

def rerun():
    raise st.ScriptRunner.RerunException(st.ScriptRequestQueue.RerunData(None))

Worked this out from the comment written over at:

# Data attached to RERUN requests
RerunData = namedtuple(
    "RerunData",
    [
        # WidgetStates protobuf to run the script with. If this is None, the
        # widget_state from the most recent run of the script will be used instead.
        "widget_state"
    ],
)

Meaning, passing None to RerunData defaults to no change in state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I run my Streamlit script?
Working with Streamlit is simple. First you sprinkle a few Streamlit commands into a normal Python script, and then you run it. We...
Read more >
Create an app - Streamlit Docs
The first step is to create a new Python script. Let's call it uber_pickups.py . · Open uber_pickups.py in your favorite IDE or...
Read more >
Streamlit rerun
Hi, I would like to rerun my app from a python script, I tried some thing like: from streamlit.ScriptRunner import RerunException
Read more >
Store Information Across App Interactions | Session State
You can now use Session State to store variables across reruns, create events on input widgets and use callback functions to handle events....
Read more >
Session State for Streamlit - Show the Community!
Perform data/image annotation; Support Pagination; Add widgets that ... of this with the simplicity of writing apps that are Python scripts!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found