Open rpomponio opened 6 months ago
Code that might help (from Chat GPT):
#!/usr/bin/env python
import dash
from dash import dcc, html, Input, Output, State
import pandas as pd
import requests
from io import StringIO
# Create Dash app
app = dash.Dash(__name__)
# App layout
app.layout = html.Div([
html.H1("CSV Downloader and Viewer"),
dcc.Input(id="url-input", type="text", placeholder="Enter URL of CSV file"),
html.Button("Download CSV", id="download-btn", n_clicks=0),
html.Div(id="output-data")
])
# Callback to download CSV file and display DataFrame
@app.callback(
Output("output-data", "children"),
[Input("download-btn", "n_clicks")],
[State("url-input", "value")]
)
def download_and_display_csv(n_clicks, url):
if n_clicks > 0 and url:
try:
# Download CSV file from URL
response = requests.get(url)
if response.status_code == 200:
# Read CSV file into DataFrame
df = pd.read_csv(StringIO(response.text))
# Display head of DataFrame
return html.Div([
html.H3("Head of DataFrame"),
html.Table([
html.Tr([html.Th(col) for col in df.columns]),
html.Tr([html.Td(df.iloc[i][col]) for col in df.columns] for i in range(min(len(df), 5)))
])
])
else:
return html.Div("Failed to download CSV file from URL.")
except Exception as e:
return html.Div(f"An error occurred: {str(e)}")
else:
return html.Div()
if __name__ == "__main__":
app.run_server(debug=True)
Instead of uploading
ticks.csv
, allow user to enter their climbing profile URL from https://mountainproject.com.For example: https://www.mountainproject.com/user/ID/NAME