Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
chore: add aggrid
Browse files Browse the repository at this point in the history
  • Loading branch information
d116626 committed Jan 24, 2024
1 parent c0c22b5 commit f330db9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 35 deletions.
84 changes: 51 additions & 33 deletions app/📣 Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import requests
import streamlit as st
from streamlit_folium import st_folium
from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode, ColumnsAutoSizeMode
from st_aggrid.shared import JsCode


st.set_page_config(layout="wide")
Expand All @@ -21,10 +23,13 @@ def get_icon_color(label: Union[bool, None]):
return "gray"


def create_map(chart_data):
def create_map(chart_data, location=None):
chart_data = chart_data.fillna("")
# center map on the mean of the coordinates
if len(chart_data) > 0:

if location is not None:
m = folium.Map(location=location, zoom_start=18)
elif len(chart_data) > 0:
m = folium.Map(
location=[chart_data["latitude"].mean(), chart_data["longitude"].mean()],
zoom_start=11,
Expand Down Expand Up @@ -106,12 +111,38 @@ def get_table_cameras_with_images(dataframe):
return table_data


def get_agrid_table(data_with_image):
# Configure AgGrid
gb = GridOptionsBuilder.from_dataframe(data_with_image)
gb.configure_selection("single", use_checkbox=False)
gb.configure_side_bar() # if you need a side bar
gb.configure_pagination(paginationAutoPageSize=False, paginationPageSize=20)

# configure individual columns
gb.configure_column(
"id_camera", header_name="ID Camera", editable=False, pinned="left"
)
gb.configure_column("emoji", header_name="", editable=False, pinned="left")
gb.configure_column("object", header_name="Objeto", editable=False)
gb.configure_column("image_url", header_name="URL Imagem")

# # Set auto size mode
grid_response = AgGrid(
data_with_image,
gridOptions=gb.build(),
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
# height=400,
# width=1200,
)

selected_row = grid_response["selected_rows"]
return selected_row


chart_data, last_update = load_alagamento_detectado_ia()
data_with_image = get_table_cameras_with_images(chart_data)

folium_map = create_map(chart_data)

## front

st.markdown("# Mapa de Alagamentos | Vision AI")
st.markdown(
Expand All @@ -122,40 +153,27 @@ def get_table_cameras_with_images(dataframe):
- Total: {len(chart_data)}
- Sucessos: {len(data_with_image)}
- Falhas:{len(chart_data) - len(data_with_image)}
Selecione uma Camera para visualizar no mapa.
""",
)

st.dataframe(
data_with_image,
column_config={
"emoji": st.column_config.Column(
"",
),
"id_camera": st.column_config.Column(
"ID Camera",
help="ID Camera",
# width="medium",
required=True,
),
"object": st.column_config.Column(
"Objeto",
help="Objeto",
# width="medium",
required=True,
),
"image_url": st.column_config.LinkColumn(
"URL Imagem",
help="ID Camera",
# width="medium",
required=True,
),
},
# hide_index=True,
use_container_width=True,
)
selected_row = get_agrid_table(data_with_image)

if selected_row:
selected_camera_id = selected_row[0]["id_camera"]
camera_data = chart_data[chart_data["id_camera"] == selected_camera_id]

if not camera_data.empty:
camera_location = [
camera_data.iloc[0]["latitude"],
camera_data.iloc[0]["longitude"],
]
folium_map = create_map(chart_data, location=camera_location)
map_data = st_folium(folium_map, key="map", height=600, width=1200)
else:
map_data = st_folium(folium_map, key="fig1", height=600, width=1200)

map_data = st_folium(folium_map, key="fig1", height=600, width=1200)

# select chart_data obj based on last_object_clicked coordinates
obj_coord = map_data["last_object_clicked"]
Expand Down
31 changes: 29 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ streamlit-folium = "^0.15.1"
streamlit-extras = "^0.3.5"
streamlit-autorefresh = "^1.0.1"
pillow = "^10.1.0"
streamlit-aggrid = "^0.3.4.post3"


[build-system]
Expand Down

0 comments on commit f330db9

Please sign in to comment.