rpomponio / climbing_viz_app

Web application for visualizing climbing pyramids (data obtained from MountainProject.com)
1 stars 1 forks source link

Alternate option for user to provide MP profile #1

Open rpomponio opened 6 months ago

rpomponio commented 6 months ago

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

rpomponio commented 5 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)