├── src ├── utils.py ├── __pycache__ │ ├── layout.cpython-39.pyc │ ├── utils.cpython-39.pyc │ └── callbacks.cpython-39.pyc ├── layout.py └── callbacks.py ├── utils ├── constants.py ├── __pycache__ │ ├── data.cpython-39.pyc │ └── constants.cpython-39.pyc └── data.py ├── app.py └── .gitignore /src/utils.py: -------------------------------------------------------------------------------- 1 | APP_LOGO = "https://observatorio.fm.usp.br/themes/Mirage/images/Logo_HCFMUSP.png" 2 | -------------------------------------------------------------------------------- /utils/constants.py: -------------------------------------------------------------------------------- 1 | APP_LOGO = "https://observatorio.fm.usp.br/themes/Mirage/images/Logo_HCFMUSP.png" 2 | -------------------------------------------------------------------------------- /src/__pycache__/layout.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turing-usp/redcap-dash/main/src/__pycache__/layout.cpython-39.pyc -------------------------------------------------------------------------------- /src/__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turing-usp/redcap-dash/main/src/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /utils/__pycache__/data.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turing-usp/redcap-dash/main/utils/__pycache__/data.cpython-39.pyc -------------------------------------------------------------------------------- /src/__pycache__/callbacks.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turing-usp/redcap-dash/main/src/__pycache__/callbacks.cpython-39.pyc -------------------------------------------------------------------------------- /utils/__pycache__/constants.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turing-usp/redcap-dash/main/utils/__pycache__/constants.cpython-39.pyc -------------------------------------------------------------------------------- /utils/data.py: -------------------------------------------------------------------------------- 1 | import awswrangler as wr 2 | 3 | 4 | path = "s3://turing-redcap-dashboard/dataset/" 5 | 6 | df = wr.s3.read_parquet(path, dataset=True) 7 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from dash import Dash 2 | import dash_bootstrap_components as dbc 3 | 4 | from src.layout import layout 5 | from src.callbacks import menu_callback, menu_title_callback 6 | 7 | 8 | app = Dash( 9 | external_stylesheets=[dbc.themes.BOOTSTRAP], 10 | title="RedCap" 11 | ) 12 | 13 | menu_callback(app) 14 | menu_title_callback(app) 15 | 16 | app.layout = layout 17 | 18 | if __name__ == '__main__': 19 | app.run_server(port=4050) 20 | -------------------------------------------------------------------------------- /src/layout.py: -------------------------------------------------------------------------------- 1 | import dash_bootstrap_components as dbc 2 | import dash_trich_components as dtc 3 | import dash_core_components as dcc 4 | import dash_html_components as html 5 | import plotly.graph_objs as go 6 | import pandas as pd 7 | from dash.dependencies import Input, Output, State 8 | from utils.constants import APP_LOGO 9 | from utils.data import df 10 | # add callback for toggling the collapse on small screens 11 | 12 | dropdown = dcc.Dropdown( 13 | id = 'plot-dropdown', 14 | options = [ 15 | {'label': 'Barplot', 'value': 'bp'}, 16 | {'label': 'Lineplot', 'value': 'lp'}, 17 | {'label': 'Scatterplot', 'value': 'sp'} 18 | ], 19 | value = 'bp' 20 | ) 21 | 22 | 23 | layout = html.Div([ 24 | dbc.Navbar( 25 | [ 26 | html.A( 27 | # Use row and col to control vertical alignment of logo / brand 28 | dbc.Row( 29 | [ 30 | dbc.Col(html.Img(src=APP_LOGO, height="30px")), 31 | dbc.Col(dbc.NavbarBrand("Hospital das Clínicas", 32 | className="ml-2", 33 | style={'font-family': 'Rockwell', 34 | 'font-size': '30px'})), 35 | ], 36 | align="center", 37 | no_gutters=True, 38 | ), 39 | ), 40 | dropdown, 41 | ], 42 | color="dark", 43 | dark=True 44 | ), 45 | html.H1(id="graph_title"), 46 | dcc.Graph(id='graph_output'), 47 | html.Div(id='menu_output') 48 | ]) 49 | -------------------------------------------------------------------------------- /src/callbacks.py: -------------------------------------------------------------------------------- 1 | import dash_bootstrap_components as dbc 2 | import dash_trich_components as dtc 3 | import dash_core_components as dcc 4 | import dash_html_components as html 5 | import dash 6 | import plotly.graph_objs as go 7 | from dash.dependencies import State, Input, Output 8 | from utils.data import df 9 | 10 | print(df.head()) 11 | 12 | 13 | def menu_callback(app): 14 | @app.callback( 15 | Output('graph_output', 'figure'), 16 | [Input('plot-dropdown', 'value')] 17 | ) 18 | def update_output(value): 19 | 20 | figure = None 21 | 22 | if value == 'bp': 23 | print(value) 24 | figure = go.Figure() 25 | figure.add_trace(go.Bar( 26 | x = df['idade'], 27 | y = df['tabagismo'], 28 | width = 2 29 | ) 30 | ) 31 | 32 | if value == "sp": 33 | print(value) 34 | figure = go.Figure() 35 | figure.add_trace(go.Scatter( 36 | x = df['idade'], 37 | y = df['tabagismo'], 38 | mode='markers' 39 | ) 40 | ) 41 | 42 | if value == "lp": 43 | print(value) 44 | figure = go.Figure() 45 | figure.add_trace(go.Scatter( 46 | x = df['idade'], 47 | y = df['tabagismo'], 48 | mode='lines' 49 | ) 50 | ) 51 | 52 | return figure 53 | 54 | 55 | def menu_title_callback(app): 56 | @app.callback( 57 | Output('graph_title', 'children'), 58 | [Input('plot-dropdown', 'value')] 59 | ) 60 | def update_output(value): 61 | 62 | name = None 63 | 64 | if value == 'bp': 65 | name = "Barplot" 66 | 67 | if value == "sp": 68 | name = "Scatterplot" 69 | 70 | if value == "lp": 71 | name = "Lineplot" 72 | 73 | return name 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ 139 | --------------------------------------------------------------------------------