Is it possible to run python code in a web browser?

Question:

My code below is a pandas dataframe, I’ve tried transcypt and flask to view this code in my browser, but have had errors. Any help would be greatly appreciated.

import pandas as pd

columns = ['cap', 'title', 'price']
df = pd.read_csv('asdawhiskey.csv', names=columns)

items = df[df['cap'] == '70cl']

print(items.to_html()) 
Asked By: tmarsh

||

Answers:

Try Streamlit. https://streamlit.io
You don’t have to write a single line of html

import streamlit as st
import pandas as pd

columns = ['cap', 'title', 'price']
df = pd.read_csv('asdawhiskey.csv', names=columns)

items = df[df['cap'] == '70cl']

st.write(items)

Then run streamlit run example.py

Answered By: Naveen Kumar

Is it possible to run python code in a web browser ? – Yes, It is now possible with the help of PyScript. Say thanks to this framework that allows users to create rich Python applications in the browser

There is no installation required. We can just use the PyScript assets served on https://pyscript.net/

Live Demo :

<html>
  <head>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
  </head>
  <body> <py-script> print('Hello, World!') </py-script> </body>
</html>

Note (As per the current official documentation) :

PyScript is very alpha and under heavy development. There are many
known issues, from usability to loading times, and you should expect
things to change often. We encourage people to play and explore with
PyScript, but at this time we do not recommend using it for
production.

Answered By: Rohìt Jíndal
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.