Create a Streamlit application that has a line chart of simulated stock prices for the last month. When a point on the line chart is clicked, display a table below with additional information about that data point.
Drop files here
or click to upload
import streamlit as st
import numpy as np
import pandas as pd
# Simulate stock prices
np.random.seed(42)
dates = pd.date_range(start="2023-09-01", end="2023-09-30", freq='D')
prices = np.random.randn(len(dates)).cumsum() + 100 # Starting price of 100
stock_data = pd.DataFrame({'Date': dates, 'Price': prices})
st.title("Simulated Stock Prices for September 2023")
# Line chart for stock prices
selected_date = st.line_chart(stock_data.set_index('Date'))
# If user selects a point,
if selected_date:
selected_index = selected_date.get('selectedpoints')
if selected_index:
selected_index = selected_index[0]
selected_price = stock_data.iloc[selected_index]
st.table(selected_price)
else:
st.write("Click on a point in the chart to see its details.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?