You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial/markdown/python/streamlit/README.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ By the end of this tutorial, you will have a working flight visualization tool a
32
32
33
33
The final app will look like this hosted Streamlit application: [Couchbase Connector Demo App](https://couchbase-connector-demo-app.streamlit.app/). The original code for this demo is available [here](https://github.com/couchbase-examples/streamlit-quickstart/blob/main/Demo.py).
34
34
35
-
## Important Concepts
35
+
## Basic Concepts
36
36
37
37
### Understanding JSON and Document Databases
38
38
Couchbase is a NoSQL document database that stores data in JSON format. This allows for flexible and scalable data modeling. JSON (JavaScript Object Notation) is a lightweight data format that is:
@@ -69,15 +69,15 @@ Couchbase organizes data into a hierarchical structure:
69
69
|**Collection**| Table | Group of related JSON documents. |
70
70
|**Document**| Row | Individual JSON record. |
71
71
72
-
### Important Operation Notes
72
+
### Operation Notes
73
73
-**CRUD Operations**: Create, Read, Update, and Delete operations only work on the specific bucket, scope, and collection specified during connection setup.
74
74
-**Queries**: Can work across any bucket, scope, and collection in the cluster, regardless of the connection settings.
75
75
-**Access Control**: Both CRUD operations and queries are limited by the permissions assigned to the Couchbase user in the cluster. The **Username** and **Password** provided during connection setup must belong to a Couchbase user with the necessary cluster access permissions.
76
76
77
77
By understanding these key concepts, you'll be well-prepared to build and optimize applications using Couchbase and Streamlit.
78
78
79
79
## Dataset Overview
80
-
The `travel-sample` dataset in Couchbase consists of multiple scopes and collections related to travel and transportation data. The primary scope used in this application is `inventory`, which contains five collections:
80
+
The [`travel-sample`](https://docs.couchbase.com/ruby-sdk/current/ref/travel-app-data-model.html) dataset in Couchbase consists of multiple scopes and collections related to travel and transportation data. The primary scope used in this application is `inventory`, which contains five collections:
81
81
82
82
-**airline (190 documents)**: Contains information about airlines, including their name, country, ICAO, IATA codes, and callsigns.
@@ -143,7 +143,7 @@ Before setting up the environment, ensure you have the following:
143
143
-**Operational Couchbase cluster** with configured access ([Instructions](https://docs.couchbase.com/cloud/get-started/connect.html#prerequisites))
144
144
-**Connection string** from Couchbase Capella
145
145
146
-
### Step 1: Installation and Setup
146
+
### Installation and Setup
147
147
Create an isolated Python environment, run the following commands:
148
148
149
149
```sh
@@ -161,8 +161,8 @@ streamlit hello
161
161
162
162
If everything is set up correctly, a browser window should open with Streamlit's demo application.
163
163
164
-
### Step 2: Implement Data Fetching Functions
165
-
To optimize performance, data retrieval functions are cached using `@st.cache_data`. This prevents redundant queries and speeds up the app.
164
+
### Implement Data Fetching Functions
165
+
To optimize performance, data retrieval functions are cached using `@st.cache_data`, which stores previously fetched data to prevent redundant queries and speed up the app. However, the `_connection` object is intentionally not cached (indicated by the underscore prefix) to ensure a fresh database connection is established each time. Caching the connection could lead to issues with stale or expired sessions, potentially causing failed queries or inconsistent data retrieval. For more details, refer to the official documentation: [Streamlit `st.cache_data`](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data).
`plot_airports_and_routes(airports_df, routes_df)`: Displays airports and their flight routes.
330
330
331
-
This function visualizes flight routes between airports using Plotly. It first extracts airport coordinates from `airports_df` into a dictionary for quick lookup. Then, it iterates through `routes_df` to collect latitude and longitude pairs for each flight route, ensuring that non-existent airports are skipped. A scatter map plot is created using `Scattermap` to represent routes as blue lines. Additionally, a separate scatter plot of airports is overlaid, with markers color-coded in red and displaying airport details on hover. The final visualization is displayed using `st.plotly_chart`.
331
+
This function visualizes flight routes between airports using [Plotly](https://plotly.com/python/lines-on-tile-maps/). It first extracts airport coordinates from `airports_df` into a dictionary for quick lookup. Then, it iterates through `routes_df` to collect latitude and longitude pairs for each flight route, ensuring that non-existent airports are skipped. A scatter map plot is created using `Scattermap` to represent routes as blue lines. Additionally, a separate scatter plot of airports is overlaid, with markers color-coded in red and displaying airport details on hover. The final visualization is displayed using `st.plotly_chart`.
`create_landmark_map(landmarks, hotels_near_landmark)`: Shows landmarks along with nearby hotels.
386
386
387
-
This function visualizes landmarks and nearby hotels on an interactive map using Plotly. Hotels are color-coded based on their distance from landmarks: red for distances ≤3 km, orange for ≤6 km, and gold for farther hotels. Each hotel is plotted with a marker, and a tooltip displays the name and distance. Landmarks are represented as blue star-shaped markers. The map uses OpenStreetMap styling and is embedded in a Streamlit app for easy visualization.
387
+
This function visualizes landmarks and nearby hotels on an interactive map using [Plotly](https://plotly.com/python/tile-scatter-maps/). Hotels are color-coded based on their distance from landmarks: red for distances ≤3 km, orange for ≤6 km, and gold for farther hotels. Each hotel is plotted with a marker, and a tooltip displays the name and distance. Landmarks are represented as blue star-shaped markers. The map uses OpenStreetMap styling and is embedded in a Streamlit app for easy visualization.
`create_hotel_map(hotels_df)`: Plots hotels, color-coded by their average ratings.
433
-
This function visualizes hotel locations on an interactive map using Plotly and Streamlit. Hotels are color-coded based on their average ratings, with a continuous color scale for rated hotels and a distinct color (orange) for those without ratings. It ensures that the map remains interactive even when no data is available by adding an invisible marker. The function also converts numeric ratings into a star-based format for better readability in the hover tooltips.
433
+
This function visualizes hotel locations on an interactive map using [Plotly](https://plotly.com/python/tile-scatter-maps/) and Streamlit. Hotels are color-coded based on their average ratings, with a continuous color scale for rated hotels and a distinct color (orange) for those without ratings. It ensures that the map remains interactive even when no data is available by adding an invisible marker. The function also converts numeric ratings into a star-based format for better readability in the hover tooltips.
1.**Airports & Flight Routes**: Users can select airports to display routes between them.
526
526
@@ -609,7 +609,7 @@ def tab3_visual():
609
609
create_hotel_map(hotels)
610
610
```
611
611
612
-
### Step 5: Putting It All Together
612
+
### Putting It All Together
613
613
614
614
In the Streamlit sidebar, users need to enter their Couchbase credentials to connect to the database. The connection is established using the `CouchbaseConnector` class.
0 commit comments