Long-time shiny user - is something like the following possible in streamlit?

I’m a long-time user of Rstudio-shiny and built some pretty big apps (e.g., Radiant – Business analytics using R and Shiny). I’m intrigued by streamlit and curious if something like the following is possible in this framework

  1. User selects values for inputs in an app
  2. Inputs are translated into python code
  3. Code is added to an AceEditor embedded in the app, after a button click
  4. Code can be re-run from the AceEditor

See the video below for a demo in my Radiant app of what I have in mind.

Alternatively, could an app be launched from a menu in jupyterlab or from a cell in a jupyterlab notebook cell, inputs get translated into python code, and the generated python code returned to be run in a jupyter notebook cell

Hi @Vincent_Nijs, welcome to the Streamlit community!

The glib answer is ‘sure, anything’s possible!’ I only skimmed the video, I think some combination of session state and the streamlit-ace package is probably what you need. The biggest thing is remembering what the inputs are (session state), and being able to generate the equivalent Python code for an operation (though, this could be a giant hassle).

Best,
Randy

Thanks for the comment @randyzwitch. After reading the below, my impression is that streamlit-ace could not access state from another part of a multi-page app. Is that correct?

Have you seen any (simple) examples of using a streamlit app to generate python code. The simplest way to do this might be with f-strings but I assume there are better ways to do this in python. Any suggestions welcome

The communication part is a subtle distinction…you can’t communicate on the browser side between components, as they are each sandboxed. However, bi-directional components can pass data back through Python.

So you can take what is passed in through Ace editor, evaluate it on the Python side, then write to another component the generated code. I don’t, unfortunately, have a good suggestion on how to generate that code, as I suspect f-strings would be pretty brittle.

Best,
Randy

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.