Trigger R Script from Streamlit UI code

Hi Team,

Iโ€™m new to developing UI and have started my journey with Streamlit. I wanted to know if can trigger/call/run an R script from my Streamlit UI code?

Objective:
I have two csv files loaded into two data frames from UI and I need to pass these two data frames to my R script saved on the working directory for processing. How can I achieve this, are there any resources to refer in the API reference documentation already?

Hi @sushantkhapekar, welcome to the Streamlit community!

How you connect with R from Python depends on your goals. You could use a package like rpy2, which lets you run some R code and get the results back in Python.

If youโ€™re just looking to use Python to trigger an R script, you could use subprocess.run to submit a shell command to run R:

https://stackoverflow.com/a/89243/2394542