Skip to content

Instantly share code, notes, and snippets.

@laranea
Forked from treuille/powers_in_dash.py
Created February 25, 2020 07:20
Show Gist options
  • Save laranea/95c48f232e88facd85b04d7100c18075 to your computer and use it in GitHub Desktop.
Save laranea/95c48f232e88facd85b04d7100c18075 to your computer and use it in GitHub Desktop.
Comparing Dash and Streamlit
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Input(
id='num',
type='number',
value=5
),
html.Table([
html.Tr([html.Td(['x', html.Sup(2)]), html.Td(id='square')]),
html.Tr([html.Td(['x', html.Sup(3)]), html.Td(id='cube')]),
html.Tr([html.Td([2, html.Sup('x')]), html.Td(id='twos')]),
html.Tr([html.Td([3, html.Sup('x')]), html.Td(id='threes')]),
html.Tr([html.Td(['x', html.Sup('x')]), html.Td(id='x^x')]),
]),
])
@app.callback(
[Output('square', 'children'),
Output('cube', 'children'),
Output('twos', 'children'),
Output('threes', 'children'),
Output('x^x', 'children')],
[Input('num', 'value')])
def callback_a(x):
return x**2, x**3, 2**x, 3**x, x**x
if __name__ == '__main__':
app.run_server(debug=True)
import streamlit as st
x = st.slider('Pick x', 1, 100, 5)
f"""
| Formula | Result |
|---------|--------|
| $x^2$ | {x**2} |
| $x^3$ | {x**3} |
| $2^x$ | {2**x} |
| $3^x$ | {3**x} |
| $x^x$ | {x**x} |
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment