Super Simple Way to Build Bitcoin Dashboard with ChatGPT – DataDrivenInvestor

Leveraging ChatGPT and Python for Effective Data Science with Bitcoing: Develop Dashboard in super fast!

There is no doubt that, one of the most important phase of a Data Science project is Data Visualization.

Creating impressive and live visuals, will give you and your project a head start.

Of course, you can create a dashboard by coding from A to Z or with smart tools like Tableau, Powerbi or Google Data Studio. Yet I am lazy today so I do not want to do that much manual laboring.

By the way if you want to use ChatGPT to create impressive visuals, do not forget to check this prompts.

So once again, lets take advantage from ChatGPT and especially it will be more attractive for you, because it includes Bitcoin too!

I dont want to spend much time, explaining to you what Data Visualization, Plotly or dash is.

You can google them, or I hope you are familiar them, but it is not necessary now.

Because we will go straight into the coding exercise.

Lets talk with ChatGPT, our loyal companion.

But you want to see dashboard and the code right away, am I right?

Lets see.

Here you can see 10.072 different coins data.You can set the time, I set it 2100 days, you will see the code below.

And also, I added 7 different time zone below the coin section

Also lets see metrics analysis tab.

Here you can see 24 hour change of market cap, which might be good indicator.

The limit really are endless, you can use;

I am not a bitcoin or financial expert, so you can find different graphs and metrics you want to add and add it to the graph by just asking ChatGPT to update its code.(Full code is at the end of the article.)

I suggest you to run first section of the code in another environment ( Jupyter Notebook might be good) to check whether the data types are correct. Because the code is too long, so when you want from ChatGPT to update the code, it might take much longer.

And also, the data types might changed because ChatGPT was updated in 2021, so it might give you outdated code, so it will good to check in somewhere else(then PyCharm), if you had an error about the datatype.

# Get the initial list of coinsresponse = requests.get('https://api.coingecko.com/api/v3/coins/list')coins_list = json.loads(response.text)coins = [coin['id'] for coin in coins_list if isinstance(coin, dict) and 'id' in coin]

# Set up Dash appapp = dash.Dash(__name__)

app.layout = html.Div([html.H1("Cryptocurrency Live Dashboard Empowered by ChatGPT", style={'text-align': 'center'}),dcc.Tabs(id="tabs", value='tab-price', children=[dcc.Tab(label='Price Analysis', value='tab-price', children=[html.Div([dcc.Dropdown(id="slct_coin",options=[{"label": coin, "value": coin} for coin in coins],multi=False,value=coins[0], # Select the first coin in the list by defaultstyle={'width': "40%"})], style={'width': '50%', 'margin': 'auto', 'padding': '10px'}),html.Div([html.Button("1M", id='btn-1m', n_clicks=0),html.Button("2M", id='btn-2m', n_clicks=0),html.Button("3M", id='btn-3m', n_clicks=0),html.Button("6M", id='btn-6m', n_clicks=0),html.Button("1Y", id='btn-1y', n_clicks=0),html.Button("2Y", id='btn-2y', n_clicks=0),html.Button("All", id='btn-all', n_clicks=0),], style={'width': '50%', 'margin': 'auto', 'padding': '10px'}),html.Div(id='output_container', children=[], style={'text-align': 'center'}),dcc.Graph(id='coin_price_graph', style={'height': '500px'})]),dcc.Tab(label='Metrics Analysis', value='tab-metrics', children=[html.Div([html.H2('Metrics Analysis', style={'text-align': 'center'}),html.Table(id='metrics_table', children=[html.Thead(html.Tr([html.Th('Metric'),html.Th('Value')])),html.Tbody([html.Tr([html.Td('Market Cap'),html.Td(id='metric-market-cap')]),html.Tr([html.Td('Volume'),html.Td(id='metric-volume')]),html.Tr([html.Td('Price'),html.Td(id='metric-price')]),html.Tr([html.Td('24h Change'),html.Td(id='metric-24h-change')]),])])], style={'width': '50%', 'margin': 'auto', 'padding': '10px'})])]),dcc.Interval(id='interval-component',interval=60 * 60 * 1000, # in milliseconds (update every hour)n_intervals=0)])

@app.callback([Output(component_id='output_container', component_property='children'),Output(component_id='coin_price_graph', component_property='figure'),Output(component_id='metrics_table', component_property='children')],[Input(component_id='slct_coin', component_property='value'),Input('btn-1m', 'n_clicks'),Input('btn-2m', 'n_clicks'),Input('btn-3m', 'n_clicks'),Input('btn-6m', 'n_clicks'),Input('btn-1y', 'n_clicks'),Input('btn-2y', 'n_clicks'),Input('btn-all', 'n_clicks'),Input('interval-component', 'n_intervals')])def update_graph(slct_coin, btn_1m, btn_2m, btn_3m, btn_6m, btn_1y, btn_2y, btn_all, n):changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]

if 'btn-1m' in changed_id:days = 30elif 'btn-2m' in changed_id:days = 60elif 'btn-3m' in changed_id:days = 90elif 'btn-6m' in changed_id:days = 180elif 'btn-1y' in changed_id:days = 365elif 'btn-2y' in changed_id:days = 730elif 'btn-all' in changed_id:days = 2100else:days = 2100 # Default time period (1 month)

if days is not None:response = requests.get(f'https://api.coingecko.com/api/v3/coins/{slct_coin}/market_chart?vs_currency=usd&days={days}&interval=daily')data = json.loads(response.text)

df = pd.DataFrame()df['times'] = pd.to_datetime([x[0] for x in data['prices']], unit='ms')df['prices'] = [x[1] for x in data['prices']]

fig = go.Figure()fig.add_trace(go.Scatter(x=df['times'], y=df['prices'], mode='lines', name='Price'))

fig.update_layout(title={'text': "Price of " + slct_coin.capitalize() + " in USD",'y': 0.95,'x': 0.5,'xanchor': 'center','yanchor': 'top'},xaxis_title="Time",yaxis_title="Price (USD)",legend_title="Variables",paper_bgcolor='rgba(240, 240, 240, 0.6)',plot_bgcolor='rgba(240, 240, 240, 0.6)',font=dict(color='black'),showlegend=False,yaxis=dict(gridcolor='lightgray'),xaxis=dict(gridcolor='lightgray'))

# Metrics analysisresponse_metrics = requests.get(f'https://api.coingecko.com/api/v3/coins/{slct_coin}')metrics_data = json.loads(response_metrics.text)market_cap = metrics_data['market_data']['market_cap']['usd']volume = metrics_data['market_data']['total_volume']['usd']price = metrics_data['market_data']['current_price']['usd']change_24h = metrics_data['market_data']['price_change_percentage_24h']

# Determine the arrow symbol and color based on the change_24h valueif change_24h < 0:arrow_symbol = ''arrow_color = 'red'else:arrow_symbol = ''arrow_color = 'green'

# Create the metrics tablemetrics_table = html.Table([html.Thead(html.Tr([html.Th('Metric'),html.Th('Value')])),html.Tbody([html.Tr([html.Td('Market Cap'),html.Td('${:,.2f}'.format(market_cap))]),html.Tr([html.Td('Volume'),html.Td('${:,.2f}'.format(volume))]),html.Tr([html.Td('Price'),html.Td('${:,.2f}'.format(price))]),html.Tr([html.Td('24h Change'),html.Td([html.Span(arrow_symbol + ' ', style={'color': arrow_color, 'font-weight': 'bold'}),html.Span('{:.2f}%'.format(change_24h), style={'display': 'inline-block'})])])])], style={'width': '100%', 'font-family': 'Arial, sans-serif', 'font-size': '16px', 'text-align': 'center'})

else:fig = go.Figure()metrics_table = html.Table([])

container = "The coin chosen by the user was: {}".format(slct_coin)

return container, fig, metrics_table

if __name__ == '__main__':app.run_server(debug=True, port=8052)

If youve made it this far, thank you! In case youre not yet a Medium member and want to expand your knowledge through reading, heres my referral link.

I continually update and add new Cheat Sheets and Source Codes for your benefit. Recently, I crafted a ChatGPT cheat sheet, and honestly, I cant recall a day when I havent used ChatGPT since its release.

Also, here is my E-Book, explains, how Machine Learning can be learned by using ChatGPT.

Feel free to select one of the Cheat Sheets or projects for me to send you by completing the forms below:

Here is my NumPy cheat sheet.

Here is the source code of the How to be a Billionaire data project.

Here is the source code of the Classification Task with 6 Different Algorithms using Python data project.

Here is the source code of the Decision Tree in Energy Efficiency Analysis data project.

Here is the source code of the DataDrivenInvestor 2022 Articles Analysis data project.

Machine learning is the last invention that humanity will ever need to make. Nick Bostrom

View original post here:

Super Simple Way to Build Bitcoin Dashboard with ChatGPT - DataDrivenInvestor

Related Posts

Comments are closed.