MarkTechPost@AI 03月06日
A Step by Step Guide to Deploy Streamlit App Using Cloudflared, BeautifulSoup, Pandas, Plotly for Real-Time Cryptocurrency Web Scraping and Visualization
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍使用多种工具构建实时加密货币追踪应用的方法,包括利用Cloudflared创建公开链接,通过Streamlit搭建应用,使用BeautifulSoup等进行数据抓取和处理,并用Plotly进行可视化,最终实现功能完备的加密货币仪表盘。

💻使用Cloudflared为Streamlit应用提供公开链接

📊通过BeautifulSoup等抓取并处理加密货币数据

🎨用Plotly实现数据可视化,包括价格对比和市值分布

🚀通过Streamlit搭建应用并在后台运行

In this tutorial, we’ll walk through a reliable and hassle-free approach using Cloudflared, a tool by Cloudflare that provides a secure, publicly accessible link to your Streamlit app. By the end of this guide, we will achieve a fully functional cryptocurrency dashboard that dynamically scrapes and visualizes real-time price data from CoinMarketCap. You can track the top 10 cryptocurrencies, compare their prices and market capitalizations, and view interactive charts for better insights.

!pip install streamlit requests beautifulsoup4 pandas matplotlib plotly!npm install -g localtunnel

First, the above command installs the necessary dependencies for building and deploying a Streamlit-based cryptocurrency dashboard. The first command installs essential Python libraries like Streamlit for the web app, BeautifulSoup4 for web scraping, Pandas for data manipulation, and Plotly for interactive visualizations. The second command installs LocalTunnel, which creates a public URL for accessing the Streamlit app from Colab.

%%writefile app.pyimport streamlit as stimport requestsfrom bs4 import BeautifulSoupimport pandas as pdimport plotly.express as px# Function to scrape cryptocurrency pricesdef scrape_crypto_prices():    url = "https://coinmarketcap.com/"    headers = {"User-Agent": "Mozilla/5.0"}    response = requests.get(url, headers=headers)       if response.status_code != 200:        return pd.DataFrame(), "Error fetching data."       soup = BeautifulSoup(response.text, "html.parser")    rows = soup.select("tbody tr")[:10]  # Get top 10 cryptocurrencies       data = []    for row in rows:        columns = row.findall("td")        name = columns[2].find("p").text  # Crypto name        symbol = columns[2].find("p", class="coin-item-symbol").text  # Symbol        price = columns[3].text  # Price        change = columns[4].text  # % Change        market_cap = columns[6].text  # Market Cap        data.append([name, symbol, price, change, market_cap])       return pd.DataFrame(data, columns=["Name", "Symbol", "Price", "% Change", "Market Cap"]), None# Streamlit UIst.title(" Live Cryptocurrency Prices")data, error = scrape_crypto_prices()if error:    st.error(error)else:    st.dataframe(data)    data["Price"] = data["Price"].replace({"$": "", ",": ""}, regex=True).astype(float)    fig = px.bar(data, x="Symbol", y="Price", color="Name", title="Top 10 Cryptos by Price")    st.plotly_chart(fig)       fig_market_cap = px.pie(data, names="Name", values="Market Cap", title="Market Cap Distribution")    st.plotly_chart(fig_market_cap)# Footerst.markdown(" Data scraped from CoinMarketCap. Updated in real-time.")

Here, we define a Streamlit web application that scrapes real-time cryptocurrency prices from CoinMarketCap and displays them in an interactive dashboard. It uses BeautifulSoup4 to extract the top 10 cryptocurrencies, including their name, symbol, price, percentage change, and market capitalization. The scraped data is processed using Pandas and visualized with Plotly. The app presents a bar chart for price comparison and a pie chart for market capitalization distribution. The app displays an error message if an error occurs while fetching data. Finally, a footer note indicates that the data updates dynamically from CoinMarketCap.

import subprocessimport time# Start Streamlit in the backgroundsubprocess.Popen(["streamlit", "run", "app.py", "--server.port=8501"])# Wait for Streamlit to starttime.sleep(5)# Start Cloudflare tunnel and expose the app!./cloudflared tunnel --url http://localhost:8501 --no-autoupdate

Finally, the above code launches the Streamlit app in the background using subprocess.Popen and allows it to run on port 8501. A short delay (time.sleep(5)) ensures the app initializes properly before starting the Cloudflared tunnel, which creates a public URL to access the app from Google Colab without authentication or additional setup.

App View
Download a CSV file of the data

In conclusion, this tutorial provided a step-by-step guide to building and deploying a real-time cryptocurrency tracking app using Streamlit, BeautifulSoup, Pandas, and Plotly. We successfully scraped live crypto data from CoinMarketCap, displayed it in an interactive dashboard, and hosted it seamlessly using Cloudflared. Unlike traditional hosting methods, this approach ensures easy deployment without authentication hassles. Whether you’re a beginner exploring web scraping and data visualization or a developer looking for a lightweight, accessible deployment method, this tutorial equips you with the tools to build and share interactive web apps efficiently.


Here is the Colab Notebook and CSV File for the above project. Also, don’t forget to follow us on Twitter and join our Telegram Channel and LinkedIn Group. Don’t Forget to join our 80k+ ML SubReddit.

Recommended Read- LG AI Research Releases NEXUS: An Advanced System Integrating Agent AI System and Data Compliance Standards to Address Legal Concerns in AI Datasets

The post A Step by Step Guide to Deploy Streamlit App Using Cloudflared, BeautifulSoup, Pandas, Plotly for Real-Time Cryptocurrency Web Scraping and Visualization appeared first on MarkTechPost.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Cloudflared Streamlit 加密货币 数据可视化
相关文章