Streamlit with OpenAI Gym

Hi all, just wondering if anyone here has experience integrating OpenAI Gym environments with Streamlit, specifically for visualizing/interacting with the environments.

I found an old project that seems to no longer be functional - https://share.streamlit.io/0.23.0-2CETv/index.html?id=5otPXhkjRTnQKWUVuwny3V . Wondering if anyone has a more updated repo that I could build off of. Thanks!

Hi @Brian,
I am not sure of the example you are referring to. I looked at some of the OpenAI Gym example and I could not get the animation to work in Streamlit. It seems OpenAI Gym opens a custom window and renders inside the window and, as far as I know, we don’t support that.

I tried:

import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action
env.close()

A possibility could be to change env.render() into something that uses a Streamlit primitive. I think it is what render_text_game in the example you posted is doing. I can see if I can get a hold of the code.

Matteo

I am also interested in using the streamlit library in collab with OpenAI Gym. Any updates on this link (it isn’t working for me at all) or the code?