Create a 3D interactive model of the solar system, using the real planets.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk
# Data for the solar system planets
planets_data = pd.DataFrame({
'planet': ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'],
'distance_from_sun': [0.39, 0.72, 1.0, 1.52, 5.2, 9.58, 19.22, 30.07], # in AU
'size': [0.383, 0.949, 1.0, 0.532, 11.21, 9.45, 4.01, 3.88] # Relative sizes
})
# Calculate coordinates (simple approximation, not to scale)
planets_data['x'] = planets_data['distance_from_sun'] * np.cos(np.linspace(0, 2 * np.pi, len(planets_data))) * 10
planets_data['y'] = planets_data['distance_from_sun'] * np.sin(np.linspace(0, 2 * np.pi, len(planets_data))) * 10
planets_data['z'] = np.zeros(len(planets_data)) # Flat plane for simplicity
# PyDeck visualization
view_state = pdk.ViewState(
longitude=0,
latitude=0,
zoom=1,
pitch=50,
)
layers = [
pdk.Layer(
'ScatterplotLayer',
data=planets_data,
get_position='[x, y, z]',
get_radius='size * 100',
get_color='[255, 204, 0]',
pickable=True,
)
]
# Create the deck
deck = pdk.Deck(
layers=layers,
initial_view_state=view_state,
tooltip={'text': '{planet}'},
)
st.title('Interactive 3D Model of the Solar System')
st.pydeck_chart(deck)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?