Spaces:
Sleeping
Sleeping
example
Browse files- Hello.py +10 -0
- LICENSE +201 -0
- README.md +37 -7
- README.md~ +23 -0
- app.py +432 -0
- pages/1_Data_Introduction.py +5 -0
- pages/2_Widget_Exploration.py +5 -0
- pages/3_Other_Tools.py +12 -0
- requirements.txt +5 -0
Hello.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
st.set_page_config(
|
| 5 |
+
page_title="Hello",
|
| 6 |
+
page_icon="👋",
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
st.sidebar.success("Select a Page")
|
| 10 |
+
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
CHANGED
|
@@ -1,14 +1,44 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.39.0
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
-
license:
|
| 11 |
-
short_description: this is a template for use in Prof. Rezapour's class
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Streamlit Template (Shadi's Class)
|
| 3 |
+
emoji: 🏢
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.39.0
|
| 8 |
+
app_file: Hello.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
# Install what you need for this notebook
|
| 16 |
+
|
| 17 |
+
It is recommended you install into a conda environment:
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
conda create -n DataVizClass python=3.10
|
| 21 |
+
conda activate DataVizClass
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Then you can install the correct packages. If you have downloaded the requirements document you can install directly with:
|
| 25 |
+
|
| 26 |
+
```
|
| 27 |
+
pip install -r /path/to/requirements.txt
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Or you can install one by one with:
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
pip install streamlit==1.39.0 altair numpy pandas matplotlib
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
To work with the VSCode interface, be sure that `jupyter` is also installed:
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
pip install jupyter
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Or you can install with `conda`.
|
| 43 |
+
|
| 44 |
+
Note that the package [Streamlit](https://streamlit.io/) that we will be working with requires we use Python scripts, so JupyterLab and/or Jupyter Notebooks won't work for this process.
|
README.md~
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Prep notebook -- My Multi-page Streamlit App (Day 2)
|
| 3 |
+
emoji: 🏢
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.39.0
|
| 8 |
+
app_file: Hello.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
# Info:
|
| 16 |
+
This is the "prep" notebook for a introductory Streamlit app for IS445.
|
| 17 |
+
|
| 18 |
+
## How to teach with this:
|
| 19 |
+
We will build this "from scratch" during class using the following steps:
|
| 20 |
+
1. Make sure your repo is cloned in your PraireLearn (this will be "is445_demo2" with my setup, "is445_demo" for each of the students)
|
| 21 |
+
1. Update the README.md if the app.py file has changed names
|
| 22 |
+
1. Copy what we did from last week to the app.py file here
|
| 23 |
+
1. Update the requirements.txt file to include libraries (see whats in here now)
|
app.py
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#######################################################
|
| 3 |
+
# 1. Getting setup -- using our HF template
|
| 4 |
+
#######################################################
|
| 5 |
+
|
| 6 |
+
# We have a few options for how to proceed. I'll start by showing the process in
|
| 7 |
+
# PL and then I'll move to my local installation of my template so that I can make
|
| 8 |
+
# sure I am pushing code at various intervals so folks can check that out.
|
| 9 |
+
|
| 10 |
+
# NOTE: during this process, you can click on "Always Rerun" for automatic updates.
|
| 11 |
+
|
| 12 |
+
# See the class notes on this with some photos for reference!
|
| 13 |
+
# **this has to be implemented!**
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
###################################################################
|
| 17 |
+
# 2. Review of where we got to last time, in template app.py file
|
| 18 |
+
###################################################################
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# Let's start by copying things we did last time
|
| 22 |
+
import streamlit as st
|
| 23 |
+
import altair as alt
|
| 24 |
+
|
| 25 |
+
# Let's recall a plot that we made with Altair in Jupyterlab:
|
| 26 |
+
# Make sure we copy the URL as well!
|
| 27 |
+
mobility_url = 'https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/mobility.csv'
|
| 28 |
+
|
| 29 |
+
st.title('This is my fancy app for HuggingFace!!')
|
| 30 |
+
|
| 31 |
+
scatters = alt.Chart(mobility_url).mark_point().encode(
|
| 32 |
+
x='Mobility:Q', # "Q for quantiative"
|
| 33 |
+
#y='Population:Q',
|
| 34 |
+
y=alt.Y('Population:Q', scale=alt.Scale(type='log')),
|
| 35 |
+
color=alt.Color('Income:Q', scale=alt.Scale(scheme='sinebow'),bin=alt.Bin(maxbins=5))
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
st.header('More complex Dashboards')
|
| 39 |
+
|
| 40 |
+
brush = alt.selection_interval(encodings=['x','y'])
|
| 41 |
+
|
| 42 |
+
chart1 = alt.Chart(mobility_url).mark_rect().encode(
|
| 43 |
+
alt.X("Student_teacher_ratio:Q", bin=alt.Bin(maxbins=10)),
|
| 44 |
+
alt.Y("State:O"),
|
| 45 |
+
alt.Color("count()")
|
| 46 |
+
).properties(
|
| 47 |
+
height=400
|
| 48 |
+
).add_params(
|
| 49 |
+
brush
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
chart2 = alt.Chart(mobility_url).mark_bar().encode(
|
| 53 |
+
alt.X("Mobility:Q", bin=True,axis=alt.Axis(title='Mobility Score')),
|
| 54 |
+
alt.Y('count()', axis=alt.Axis(title='Mobility Score Distribution'))
|
| 55 |
+
).transform_filter(
|
| 56 |
+
brush
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
chart = (chart1.properties(width=300) | chart2.properties(width=300))
|
| 60 |
+
|
| 61 |
+
tab1, tab2 = st.tabs(["Mobility interactive", "Scatter plot"])
|
| 62 |
+
|
| 63 |
+
with tab1:
|
| 64 |
+
st.altair_chart(chart, theme=None, use_container_width=True)
|
| 65 |
+
with tab2:
|
| 66 |
+
st.altair_chart(scatters, theme=None, use_container_width=True)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
################################################
|
| 70 |
+
# 3. Adding features, Pushing to HF
|
| 71 |
+
################################################
|
| 72 |
+
|
| 73 |
+
st.header('Requirements, README file, Pushing to HuggingFace')
|
| 74 |
+
|
| 75 |
+
### 3.1 Make a plot ###
|
| 76 |
+
|
| 77 |
+
# Let's say we want to add in some matplotlib plots from some data we read
|
| 78 |
+
# in with Pandas.
|
| 79 |
+
|
| 80 |
+
import pandas as pd
|
| 81 |
+
df = pd.read_csv(mobility_url)
|
| 82 |
+
|
| 83 |
+
# There are a few ways to show the dataframe if we want our viewer to see the table:
|
| 84 |
+
#df
|
| 85 |
+
st.write(df)
|
| 86 |
+
|
| 87 |
+
# Now, let's plot with matplotlib:
|
| 88 |
+
import matplotlib.pyplot as plt
|
| 89 |
+
|
| 90 |
+
fig, ax = plt.subplots()
|
| 91 |
+
df['Seg_income'].plot(kind='hist', ax=ax)
|
| 92 |
+
#plt.show() # but wait! this doesn't work!
|
| 93 |
+
|
| 94 |
+
# We need to use the streamlit-specific way of showing matplotlib plots: https://docs.streamlit.io/develop/api-reference/charts/st.pyplot
|
| 95 |
+
st.pyplot(fig)
|
| 96 |
+
|
| 97 |
+
### 3.2 Push these changes to HF -- requirements.txt ###
|
| 98 |
+
# In order to push these changes to HF and have things actually show up we need to
|
| 99 |
+
# add the packages we've added to our requirements.txt file.
|
| 100 |
+
|
| 101 |
+
st.write('''The requirements.txt file contains all the packages needed
|
| 102 |
+
for our app to run. These include (for our application):''')
|
| 103 |
+
st.code('''
|
| 104 |
+
streamlit==1.39.0
|
| 105 |
+
altair
|
| 106 |
+
numpy
|
| 107 |
+
pandas
|
| 108 |
+
matplotlib
|
| 109 |
+
''')
|
| 110 |
+
|
| 111 |
+
# NOTE: for any package you want to use in your app.py file, you must include it in
|
| 112 |
+
# the requirements.txt file!
|
| 113 |
+
|
| 114 |
+
# Note #2: we specified a version of streamlit so we can use some specific widgets
|
| 115 |
+
|
| 116 |
+
### 3.3 Push these changes to HF -- README.md ###
|
| 117 |
+
|
| 118 |
+
# While we're doing this, let's also take a look at the README.md file!
|
| 119 |
+
|
| 120 |
+
st.header('Build in HF: README.md & requirements.txt files')
|
| 121 |
+
|
| 122 |
+
st.code('''
|
| 123 |
+
---
|
| 124 |
+
title: Prep notebook -- My Streamlit App
|
| 125 |
+
emoji: 🏢
|
| 126 |
+
colorFrom: blue
|
| 127 |
+
colorTo: gray
|
| 128 |
+
sdk: streamlit
|
| 129 |
+
sdk_version: 1.39.0
|
| 130 |
+
app_file: app.py
|
| 131 |
+
pinned: false
|
| 132 |
+
license: mit
|
| 133 |
+
---
|
| 134 |
+
''')
|
| 135 |
+
st.write("Note: the sdk version has to match what is in your requirements.txt (and with whatever widgets you want to be able to use).")
|
| 136 |
+
|
| 137 |
+
# Some important things to note here:
|
| 138 |
+
|
| 139 |
+
st.write('Some important items to note about these:')
|
| 140 |
+
st.markdown('''
|
| 141 |
+
* the "emoji" is what will show up as an identifier on your homepage
|
| 142 |
+
* the sdk *must* be streamlit
|
| 143 |
+
* the "app_file" *must* link to the app file you are developing in
|
| 144 |
+
''')
|
| 145 |
+
|
| 146 |
+
################################################
|
| 147 |
+
# 4. TODO Quick intro to widgets
|
| 148 |
+
################################################
|
| 149 |
+
|
| 150 |
+
st.header('Widgets in Streamlit apps')
|
| 151 |
+
|
| 152 |
+
### 4.1 Widget basics: A few widget examples ###
|
| 153 |
+
|
| 154 |
+
st.markdown("""
|
| 155 |
+
These will be very similar to how we used the `ipywidgets` package in Jupyter notebooks.
|
| 156 |
+
""")
|
| 157 |
+
|
| 158 |
+
st.markdown("""
|
| 159 |
+
We won't go over all of them, but you can check out the [list of widgets](https://docs.streamlit.io/develop/api-reference/widgets)
|
| 160 |
+
linked.
|
| 161 |
+
""")
|
| 162 |
+
|
| 163 |
+
st.markdown("""Let's try a few!""")
|
| 164 |
+
|
| 165 |
+
st.subheader('Feedback Widget')
|
| 166 |
+
|
| 167 |
+
st.markdown("""
|
| 168 |
+
For example, we could try the [feedback widget](https://docs.streamlit.io/develop/api-reference/widgets/st.feedback).
|
| 169 |
+
"""
|
| 170 |
+
)
|
| 171 |
+
st.markdown("""
|
| 172 |
+
If we check out the docs for this widget, we see some familiar looking functions like
|
| 173 |
+
`on_change` and the example they give looks very similar to an
|
| 174 |
+
"observation" function that we built before using widgets:
|
| 175 |
+
""")
|
| 176 |
+
|
| 177 |
+
st.code(
|
| 178 |
+
"""
|
| 179 |
+
sentiment_mapping = ["one", "two", "three", "four", "five"]
|
| 180 |
+
selected = st.feedback("stars")
|
| 181 |
+
if selected is not None:
|
| 182 |
+
st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")
|
| 183 |
+
""")
|
| 184 |
+
|
| 185 |
+
# Let's give this a shot!
|
| 186 |
+
|
| 187 |
+
st.write("How great are you feeling right now?")
|
| 188 |
+
sentiment_mapping = ["one", "two", "three", "four", "five"] # map to these numers
|
| 189 |
+
selected = st.feedback("stars")
|
| 190 |
+
if selected is not None: # make sure we have a selection
|
| 191 |
+
st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")
|
| 192 |
+
if selected < 1:
|
| 193 |
+
st.markdown('Sorry to hear you are so sad :(')
|
| 194 |
+
elif selected < 3:
|
| 195 |
+
st.markdown('A solid medium is great!')
|
| 196 |
+
else:
|
| 197 |
+
st.markdown('Fantastic you are having such a great day!')
|
| 198 |
+
|
| 199 |
+
st.subheader('Radio Buttons')
|
| 200 |
+
|
| 201 |
+
st.markdown("""
|
| 202 |
+
Let's try out a [radio button](https://docs.streamlit.io/develop/api-reference/widgets/st.radio) example.
|
| 203 |
+
""")
|
| 204 |
+
|
| 205 |
+
favoriteViz = st.radio(
|
| 206 |
+
"What's your visualization tool so far?",
|
| 207 |
+
[":rainbow[Streamlit]", "vega-lite :sparkles:", "matplotlib :material/Home:"],
|
| 208 |
+
captions=[
|
| 209 |
+
"New and cool!",
|
| 210 |
+
"So sparkly.",
|
| 211 |
+
"Familiar and comforting.",
|
| 212 |
+
],
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
if favoriteViz == ":rainbow[Streamlit]":
|
| 216 |
+
st.write("You selected Streamlit!")
|
| 217 |
+
else:
|
| 218 |
+
st.write("You didn't select Streamlit but that's ok, Data Viz still likes you :grin:")
|
| 219 |
+
|
| 220 |
+
st.markdown("""
|
| 221 |
+
Note here that we made use of text highlight [colors](https://docs.streamlit.io/develop/api-reference/text/st.markdown)
|
| 222 |
+
and [emoji's](https://streamlit-emoji-shortcodes-streamlit-app-gwckff.streamlit.app/)
|
| 223 |
+
and [icons](https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded).
|
| 224 |
+
""")
|
| 225 |
+
|
| 226 |
+
### 4.2 Connecting widgets with plots ###
|
| 227 |
+
|
| 228 |
+
st.subheader('Connecting Widgets and Plots')
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
st.markdown("""
|
| 232 |
+
There are actually [many types of charts](https://docs.streamlit.io/develop/api-reference/charts)
|
| 233 |
+
supported in Streamlit (including the Streamlit-based "Simple Charts"),
|
| 234 |
+
though we will just mainly be focusing on [Altair-related](https://docs.streamlit.io/develop/api-reference/charts/st.altair_chart) plots
|
| 235 |
+
and their interactivity options since we'll also be making use of these when
|
| 236 |
+
we move to building Jekyll webpages.
|
| 237 |
+
""")
|
| 238 |
+
|
| 239 |
+
st.markdown("""Since `matplotlib` is relatively familiar though, let's do a quick
|
| 240 |
+
example using `pandas` and `matplotlib` to plot as
|
| 241 |
+
Streamlit [does support `matplotlib`](https://docs.streamlit.io/develop/api-reference/charts/st.pyplot)
|
| 242 |
+
as a plotting engine. """)
|
| 243 |
+
|
| 244 |
+
st.markdown("""First, let's just make a simple plot with `pandas` and `matplotlib`.
|
| 245 |
+
Let's re-do the matplotlib plots we did before with the mobility dataset
|
| 246 |
+
with some interactivity. """)
|
| 247 |
+
|
| 248 |
+
import pandas as pd
|
| 249 |
+
import numpy as np
|
| 250 |
+
|
| 251 |
+
# first, let's make a static plot:
|
| 252 |
+
st.write("We'll start with a static plot:")
|
| 253 |
+
# read in dataset
|
| 254 |
+
df = pd.read_csv("https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/mobility.csv")
|
| 255 |
+
|
| 256 |
+
# make bins along student-teacher ratio
|
| 257 |
+
bins = np.linspace(df['Student_teacher_ratio'].min(),df['Student_teacher_ratio'].max(), 10)
|
| 258 |
+
|
| 259 |
+
# make pivot table
|
| 260 |
+
table = df.pivot_table(index='State', columns=pd.cut(df['Student_teacher_ratio'], bins), aggfunc='size')
|
| 261 |
+
|
| 262 |
+
# our plotting code before was:
|
| 263 |
+
st.code("""
|
| 264 |
+
import matplotlib.pyplot as plt
|
| 265 |
+
|
| 266 |
+
fig,ax = plt.subplots(figsize=(10,8))
|
| 267 |
+
ax.imshow(table.values, cmap='hot', interpolation='nearest')
|
| 268 |
+
ax.set_yticks(range(len(table.index)))
|
| 269 |
+
ax.set_yticklabels(table.index)
|
| 270 |
+
plt.show()
|
| 271 |
+
""")
|
| 272 |
+
|
| 273 |
+
st.write("Let's translate it into something that will work with Streamlit:")
|
| 274 |
+
|
| 275 |
+
import matplotlib.pyplot as plt
|
| 276 |
+
|
| 277 |
+
fig,ax = plt.subplots() # this changed
|
| 278 |
+
ax.imshow(table.values, cmap='hot', interpolation='nearest')
|
| 279 |
+
ax.set_yticks(range(len(table.index)))
|
| 280 |
+
ax.set_yticklabels(table.index)
|
| 281 |
+
|
| 282 |
+
st.pyplot(fig) # this is different
|
| 283 |
+
|
| 284 |
+
st.markdown("""But this is too big! The trick is that we can save this as a buffer: """)
|
| 285 |
+
|
| 286 |
+
from io import BytesIO
|
| 287 |
+
|
| 288 |
+
fig,ax = plt.subplots(figsize=(4,8)) # this changed
|
| 289 |
+
ax.imshow(table.values, cmap='hot', interpolation='nearest')
|
| 290 |
+
ax.set_yticks(range(len(table.index)))
|
| 291 |
+
ax.set_yticklabels(table.index)
|
| 292 |
+
|
| 293 |
+
buf = BytesIO()
|
| 294 |
+
fig.tight_layout()
|
| 295 |
+
fig.savefig(buf, format="png")
|
| 296 |
+
st.image(buf, width = 500) # can mess around with width, figsize/etc
|
| 297 |
+
|
| 298 |
+
st.write("Now, let's make this interactive.")
|
| 299 |
+
st.markdown("""We'll first use the [multiselect](https://docs.streamlit.io/develop/api-reference/widgets/st.multiselect)
|
| 300 |
+
tool in order to allow for multiple state selection. """)
|
| 301 |
+
|
| 302 |
+
# vertical alignment so they end up side by side
|
| 303 |
+
fig_col, controls_col = st.columns([2,1], vertical_alignment='center')
|
| 304 |
+
|
| 305 |
+
# multi-select
|
| 306 |
+
states_selected = controls_col.multiselect('Which states do you want to view?', table.index.values)
|
| 307 |
+
|
| 308 |
+
if len(states_selected) > 0:
|
| 309 |
+
df_subset = df[df['State'].isin(states_selected)] # changed
|
| 310 |
+
|
| 311 |
+
# make pivot table -- changed
|
| 312 |
+
table_sub = df_subset.pivot_table(index='State',
|
| 313 |
+
columns=pd.cut(df_subset['Student_teacher_ratio'], bins),
|
| 314 |
+
aggfunc='size')
|
| 315 |
+
|
| 316 |
+
base_size = 4
|
| 317 |
+
# this resizing doesn't 100% work great
|
| 318 |
+
#factor = len(table.index)*1.0/df['State'].nunique()
|
| 319 |
+
#if factor == 0: factor = 1 # for non-selections
|
| 320 |
+
#fig,ax = plt.subplots(figsize=(base_size,2*base_size*factor)) # this changed too for different size
|
| 321 |
+
fig,ax = plt.subplots(figsize=(base_size,2*base_size)) # this changed too for different size
|
| 322 |
+
# extent is (xmin, xmax, ymax (buttom), ymin (top))
|
| 323 |
+
extent = [bins.min(), bins.max(), 0, len(table_sub.index)]
|
| 324 |
+
ax.imshow(table_sub.values, cmap='hot', interpolation='nearest',
|
| 325 |
+
extent=extent)
|
| 326 |
+
ax.set_yticks(range(len(table_sub.index)))
|
| 327 |
+
ax.set_yticklabels(table_sub.index)
|
| 328 |
+
#ax.set_xticklabels(bins)
|
| 329 |
+
|
| 330 |
+
buf = BytesIO()
|
| 331 |
+
fig.tight_layout()
|
| 332 |
+
fig.savefig(buf, format="png")
|
| 333 |
+
fig_col.image(buf, width = 400) # changed here to fit better
|
| 334 |
+
else:
|
| 335 |
+
fig,ax = plt.subplots(figsize=(4,8)) # this changed
|
| 336 |
+
extent = [bins.min(), bins.max(), 0, len(table.index)]
|
| 337 |
+
ax.imshow(table.values, cmap='hot', interpolation='nearest', extent=extent)
|
| 338 |
+
ax.set_yticks(range(len(table.index)))
|
| 339 |
+
ax.set_yticklabels(table.index)
|
| 340 |
+
#ax.set_xticklabels(bins)
|
| 341 |
+
|
| 342 |
+
buf = BytesIO()
|
| 343 |
+
fig.tight_layout()
|
| 344 |
+
fig.savefig(buf, format="png")
|
| 345 |
+
fig_col.image(buf, width = 500) # can mess around with width, figsize/etc
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
st.markdown("""
|
| 349 |
+
Now let's add more in by including a [range slider](https://docs.streamlit.io/develop/api-reference/widgets/st.slider)
|
| 350 |
+
widget.
|
| 351 |
+
""")
|
| 352 |
+
|
| 353 |
+
# vertical alignment so they end up side by side
|
| 354 |
+
fig_col2, controls_col2 = st.columns([2,1], vertical_alignment='center')
|
| 355 |
+
|
| 356 |
+
# multi-select
|
| 357 |
+
states_selected2 = controls_col2.multiselect('Which states do you want to view?',
|
| 358 |
+
table.index.values, key='unik1155')
|
| 359 |
+
# had to pass unique key to have double widgets with same value
|
| 360 |
+
|
| 361 |
+
# range slider -- added
|
| 362 |
+
student_teacher_ratio_range = controls_col2.slider("Range of student teacher ratio:",
|
| 363 |
+
df['Student_teacher_ratio'].min(),
|
| 364 |
+
df['Student_teacher_ratio'].max(),
|
| 365 |
+
(0.25*df['Student_teacher_ratio'].mean(),
|
| 366 |
+
0.75*df['Student_teacher_ratio'].mean()))
|
| 367 |
+
|
| 368 |
+
# note all the "2's" here, probably will just update the original one
|
| 369 |
+
if len(states_selected2) > 0: # here we set a default value for the slider, so no need to have a tag
|
| 370 |
+
min_range = student_teacher_ratio_range[0] # added
|
| 371 |
+
max_range = student_teacher_ratio_range[1] # added
|
| 372 |
+
|
| 373 |
+
df_subset2 = df[(df['State'].isin(states_selected2)) & (df['Student_teacher_ratio'] >= min_range) & (df['Student_teacher_ratio']<=max_range)] # changed
|
| 374 |
+
|
| 375 |
+
# just 10 bins over the full range --> changed
|
| 376 |
+
bins2 = 10 #np.linspace(df['Student_teacher_ratio'].min(),df['Student_teacher_ratio'].max(), 10)
|
| 377 |
+
|
| 378 |
+
# make pivot table -- changed
|
| 379 |
+
table_sub2 = df_subset2.pivot_table(index='State',
|
| 380 |
+
columns=pd.cut(df_subset2['Student_teacher_ratio'], bins2),
|
| 381 |
+
aggfunc='size')
|
| 382 |
+
|
| 383 |
+
base_size = 4
|
| 384 |
+
fig2,ax2 = plt.subplots(figsize=(base_size,2*base_size)) # this changed too for different size
|
| 385 |
+
extent2 = [df_subset2['Student_teacher_ratio'].min(),
|
| 386 |
+
df_subset2['Student_teacher_ratio'].max(),
|
| 387 |
+
0, len(table_sub2.index)]
|
| 388 |
+
ax2.imshow(table_sub2.values, cmap='hot', interpolation='nearest', extent=extent2)
|
| 389 |
+
ax2.set_yticks(range(len(table_sub2.index)))
|
| 390 |
+
ax2.set_yticklabels(table_sub2.index)
|
| 391 |
+
#ax2.set_xticklabels()
|
| 392 |
+
|
| 393 |
+
buf2 = BytesIO()
|
| 394 |
+
fig2.tight_layout()
|
| 395 |
+
fig2.savefig(buf2, format="png")
|
| 396 |
+
fig_col2.image(buf2, width = 400) # changed here to fit better
|
| 397 |
+
else:
|
| 398 |
+
min_range = student_teacher_ratio_range[0] # added
|
| 399 |
+
max_range = student_teacher_ratio_range[1] # added
|
| 400 |
+
|
| 401 |
+
df_subset2 = df[(df['Student_teacher_ratio'] >= min_range) & (df['Student_teacher_ratio']<=max_range)] # changed
|
| 402 |
+
|
| 403 |
+
# just 10 bins over the full range --> changed
|
| 404 |
+
bins2 = 10 #np.linspace(df['Student_teacher_ratio'].min(),df['Student_teacher_ratio'].max(), 10)
|
| 405 |
+
|
| 406 |
+
# make pivot table -- changed
|
| 407 |
+
table_sub2 = df_subset2.pivot_table(index='State',
|
| 408 |
+
columns=pd.cut(df_subset2['Student_teacher_ratio'], bins2),
|
| 409 |
+
aggfunc='size')
|
| 410 |
+
|
| 411 |
+
base_size = 4
|
| 412 |
+
fig2,ax2 = plt.subplots(figsize=(base_size,2*base_size)) # this changed too for different size
|
| 413 |
+
extent2 = [df_subset2['Student_teacher_ratio'].min(),
|
| 414 |
+
df_subset2['Student_teacher_ratio'].max(),
|
| 415 |
+
0, len(table_sub2.index)]
|
| 416 |
+
ax2.imshow(table_sub2.values, cmap='hot', interpolation='nearest', extent=extent2)
|
| 417 |
+
ax2.set_yticks(range(len(table_sub2.index)))
|
| 418 |
+
ax2.set_yticklabels(table_sub2.index)
|
| 419 |
+
#ax2.set_xticklabels()
|
| 420 |
+
|
| 421 |
+
buf2 = BytesIO()
|
| 422 |
+
fig2.tight_layout()
|
| 423 |
+
fig2.savefig(buf2, format="png")
|
| 424 |
+
fig_col2.image(buf2, width = 400) # changed here to fit better
|
| 425 |
+
|
| 426 |
+
st.header('Push final page to HF')
|
| 427 |
+
st.markdown("""When ready, do:""")
|
| 428 |
+
st.code("""
|
| 429 |
+
git add -A
|
| 430 |
+
git commit -m "final push of day 1"
|
| 431 |
+
git push
|
| 432 |
+
""")
|
pages/1_Data_Introduction.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.set_page_config(page_title="Introduction to Data", page_icon=":1234:") # not sure what this adds?
|
| 4 |
+
st.sidebar.header("Introduction to Data")
|
| 5 |
+
|
pages/2_Widget_Exploration.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.set_page_config(page_title="Widget Exploration", page_icon=":1234:")
|
| 4 |
+
st.sidebar.header("Widget Exploration")
|
| 5 |
+
|
pages/3_Other_Tools.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.set_page_config(page_title="Other Tools", page_icon=":1234:")
|
| 4 |
+
st.sidebar.header("Other Tools")
|
| 5 |
+
|
| 6 |
+
st.title("Other cool things to check out")
|
| 7 |
+
|
| 8 |
+
st.markdown(""" While we won't have time to cover everything, a few things you might want to check out later:
|
| 9 |
+
1. You can connect databases to Streamlit [like AWS, MongoDB, etc](https://docs.streamlit.io/develop/tutorials/databases)
|
| 10 |
+
1. You can embed Streamlit Spaces [within other webpages](https://huggingface.co/docs/hub/en/spaces-sdks-streamlit#embed-streamlit-spaces-on-other-webpages)
|
| 11 |
+
1. If you have models hosted on HuggingFace, you can build [apps that use those models](https://huggingface.co/blog/streamlit-spaces) (like LLMs) and let others use them.
|
| 12 |
+
""")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.39.0
|
| 2 |
+
altair
|
| 3 |
+
numpy
|
| 4 |
+
pandas
|
| 5 |
+
matplotlib
|