Py.Cafe

vinicius.camargo/

streamlit-on-pycafe

Streamlit on Py.cafe: Interactive Features Showcase

DocsPricing
  • DataCirclePodcast.csv
  • Podecst_dados.csv
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import streamlit as st
import pandas as pd
import altair as alt

# Carregar o dataset
try:
    df = pd.read_csv("DataCirclePodcast.csv", sep=',')
except FileNotFoundError:
    st.error("The file 'DataCirclePodcast.csv' was not found. Please upload the correct file.")
    st.stop()

# Título do app
st.title("AE MeetUp - Building an App with Streamlit")

# Mensagem inicial
st.markdown(
    """
Hello, MAE! Let's start this adventure?
"""
)

# Mostrar o DataFrame
st.header("Reading the Dataset")
st.dataframe(df)

# Verificar se as colunas necessárias existem no DataFrame
if "Título do episódio" in df.columns and "Reproduções" in df.columns:
    # Adicionar filtro de lista suspensa
    st.subheader("Filter by Episode Title")
    selected_episode = st.selectbox(
        "Select an episode to filter:",
        options=["All"] + df["Título do episódio"].drop_duplicates().tolist()
    )
    
    # Filtrar o DataFrame com base na seleção
    if selected_episode != "All":
        filtered_df = df[df["Título do episódio"] == selected_episode]
    else:
        filtered_df = df
    
    # Criar o gráfico de barras com Altair
    if not filtered_df.empty:
        chart = (
            alt.Chart(filtered_df)
            .mark_bar()
            .encode(
                x=alt.X("Título do episódio", sort='-y', title="Episode Title"),
                y=alt.Y("Reproduções", title="Reproductions"),
                tooltip=["Título do episódio", "Reproduções"]
            )
            .properties(
                width=800,  # Largura do gráfico
                height=400,  # Altura do gráfico
                title="Reproductions per Episode"
            )
        )

        # Exibir o gráfico
        st.altair_chart(chart, use_container_width=True)
    else:
        st.warning("No data to display for the selected episode.")
else:
    st.error("The dataset must have columns named 'Título do episódio' and 'Reproduções'.")

# Final Message
st.title("Now it's your time!")

# Final Message2
st.markdown(
    """
Use your creativity, the streamlit library, and your BFF, Chat GPT, to help you develop an amazing app!
"""
)

df = df.fillna(0)
df['popularidade'] = df['Reproduções'] * 0.25 + df['Curtidas'] * 0.25 + df['Comentários'] * 0.25 + df['Compartilhamentos'] * 0.25


# df = df.drop(index=0)

chart_1 = (
            alt.Chart(filtered_df)
            .mark_bar()
            .encode(
                x=alt.X("Estúdio", sort='-y', title="Estúdio flag"),
                y=alt.Y("Reproduções", title="Reproductions"),
                tooltip=["Estudio", "Reproduções"]
            )
            .properties(
                width=800,  # Largura do gráfico
                height=400,  # Altura do gráfico
                title="Reproductions per Flag Esttudio"
            )
        )
# Exibir o gráfico
st.altair_chart(chart_1, use_container_width=True)