Course: Big Data - IU S23
Author: Firas Jolha
You can easily install streamlit
version 0.55.2
via pip
. You just need to run the command:
We used the option --ignore-installed
to avoid issues during installation.
Note: When you install a new package in Python 2.7, If pip
gives the follwing error:
Then add the line nameserver 8.8.8.8
to the file /etc/resolv.conf
.
For the project purposes, you have to display at least the results of EDA and PDA, in addition to data characteristics but try to build a cool dashboard for your project. We can import the package streamlit
as follows:
As we know that the analysis results are stored as csv files and here we can read them as Pandas or Spark DataFrame as follows:
st.write
st.write
is used to display information into your Streamlit app. It does different things depending on what you throw at it. Unlike other Streamlit commands, write() has some unique properties:
We can print some text on the dashboard.
\n
if you need to use it.We can display a dataframe as follows:
We can display Altair charts as follows:
Streamlit provides specific functions for different text elements but st.write
can be used to perform similar jobs.
st.markdown
Display string formatted as Markdown.
st.divider
is not supported in Streamlit v0.55.2 but we can use st.markdown("---")
for adding dividers.
The function st.markdown(body, unsafe_allow_html = False)
has an argument unsafe_allow_html
which can be used to add html tags to the dashboard. By default, any HTML tags found in the body will be escaped and therefore treated as pure text. This behavior may be turned off by setting this argument to True
.
That said, the package authors strongly advise against it. It is hard to write secure HTML, so by using this argument you may be compromising your users' security. Only for this project, it is fine to use it.
st.title
Display text in title formatting. Each document should have a single st.title(), although this is not enforced.
As you can see, we can not write markdown text for the title. This function will not change the title of the dashboard.
st.header
Display text in header formatting.
st.subheader
Display text in subheader formatting.
st.code
Display a code block with optional syntax highlighting.
st.text
Write fixed-width and preformatted text.
st.latex
Display mathematical expressions formatted as LaTeX. Supported LaTeX functions are listed at Katex.org.
When you're working with data, it is extremely valuable to visualize that data quickly, interactively, and from multiple different angles. That's what Streamlit is actually built and optimized for.
There are two main functions for displaying the dataframes. st.dataframe
displays the dataframe as an interactive table whereas st.table
displays the dataframe as a static table.
It is recommended to build charts using Altair or Matplotlib packages since the Streamlit package provides only limited settings then display the charts via st.pyplot
or st.altair_chart
respectively. Indeed you can add css
styles to your dashboard as follows:
You can add images to the dashboard via st.image
function.
Streamlit provides a few methods that allow you to add animation to your apps. These animations include progress bars, status messages (like warnings), and celebratory balloons.
With widgets, Streamlit allows you to bake interactivity directly into your apps with buttons, sliders, text inputs, and more.
st.button
Display a button widget.
st.checkbox
Display a checkbox widget.
st.radio
and st.selectbox
st.radio
displays a radio button widget.
st.text_input
and st.number_input
st.text_input
displays a single-line text input widget. st.number_input
displays a numeric input widget.
st.date_input
and st.time_input
st.date_input
displays a date input widget. st.time_input
displays a time input widget.
HDP comes with a list of custom ports and you can check them by looking at the prots forwarded in virtual box
or docker
.
We will use the first port 60000
for Streamlit server. By default, Streamlit uses port 8501
, but you can run it on a custom port by specifying the server port as follows:
streamlit run <streamlit_app.py> --server.port 60000
Here we are running the Streamlit app in <streamlit_app.py>
on the port 60000. You can open a web tab on your local machine for localhost:60000
to view the Streamlit app.