Got this error while deploying web app

Summary

FileNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)File "/app/adidas_us_sales/Adidas.py", line 31, in <module>
    df = pd.read_excel("C:/Users/Shubham/Desktop/Dash/adidas.xlsx")File "/home/appuser/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 482, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 1652, in __init__
    ext = inspect_excel_format(File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 1525, in inspect_excel_format
    with get_handle(File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/common.py", line 865, in get_handle
    handle = open(handle, ioargs.mode)

Hello, could you please read through this post and add some more details, especially the code you are using?

Based on only what you’ve posted, it looks like you’re trying to read the excel file from your local computer "C:/Users/Shubham/Desktop/Dash/adidas.xlsx". To make it work when deployed, you will have to change that path to be the relative location of that file (e.g. "adidas.xlsx" if it’s in the same folder as your app), and make sure you add it to your github repository.

I did that but still same error shows
ImportError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)File "/app/mlp-project/Adidas.py", line 30, in <module>
    df = pd.read_excel("adidas.xlsx")File "/home/appuser/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 482, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_base.py", line 1695, in __init__
    self._reader = self._engines[engine](self._io, storage_options=storage_options)File "/home/appuser/venv/lib/python3.9/site-packages/pandas/io/excel/_openpyxl.py", line 556, in __init__
    import_optional_dependency("openpyxl")File "/home/appuser/venv/lib/python3.9/site-packages/pandas/compat/_optional.py", line 144, in import_optional_dependency
    raise ImportError(msg)

here is my code
import pandas as pd
import plotly.express as px
import streamlit as st
from PIL import Image
import plotly.graph_objects as go
import matplotlib.pyplot as plt

In[2]:

st.set_page_config(page_title=“Adidas sales Dashboard”,
page_icon=“bar_chart:”,
layout=“wide”)

In:

In[14]:

df = pd.read_excel(“adidas.xlsx”)

#df = pd.read_excel(“C:/Users/Shubham/Desktop/Dash/adidas.xlsx”)

df1=df.sort_values(“Price per Unit”)

In[15]:

df = df.set_index(“Retailer”)

In[12]:

#st.dataframe(df)

In[10]:

#pie_chart=px.pie(df, title=‘Price per Unit’, values=‘Units Sold’, names=‘Product’)
#pie_chart

In[11]:

#fig=px.bar(df, x=“Region”, y=“Units Sold”, color=“City”, title=“dghdg”)
#fig.show()

In[17]:

st.sidebar.header(‘Please Filter Here:’)
Region = st.sidebar.multiselect(
“Select the Region:”,
options=df[“Region”].unique(),
default=df[“Region”].unique())

In:

Product = st.sidebar.multiselect(
“Select the store:”,
options=df[“Product”].unique(),
default=df[“Product”].unique())

Sales_Method = st.sidebar.multiselect(
“Select the store:”,
options=df[“Sales_Method”].unique(),
default=df[“Sales_Method”].unique())

In:

df_selection = df1.query(
“Region ==@Region & Product ==@Product & Sales_Method ==@Sales_Method”)
st.dataframe(df_selection)

In:

st.title(‘Adidas US Sales’)
st.markdown(‘##’)
total_sales= int(df_selection[‘Units_Sold’].sum())
average_Price= round(df_selection[“Price per Unit”].mean(),1)
average_sales = round(df_selection[‘Total_Sales’].mean(),2)

left_column, middle_column, right_column= st.columns(3)
with left_column:
st.subheader(‘Total_Sales’)
st.subheader(f’US ${total_sales:,}‘)
with middle_column:
st.subheader(‘Average Price’)
st.subheader(f’US ${average_Price:,}’)
with right_column:
st.subheader(‘Average sales’)
st.subheader(f’US ${average_sales:,}')
st.markdown(“—”)

sales_by_product = df_selection.groupby(by=[‘Product’]).sum()[[‘Total_Sales’]].sort_values(by=[‘Total_Sales’], ascending=False)
fig_Product_sales = px.bar(
sales_by_product,
x=‘Total_Sales’, y = sales_by_product.index,
orientation=‘h’, title=“Sales by Product”,
color_discrete_sequence=[“#0083B8”]* len(sales_by_product),
template=“plotly_white”,)

#fig_Product_sales.update_layout(plot_bgcolor=“rgba(0,0,0,0)”,

xasis=(dict(showgrid=False)))

bar_chart=px.bar(df_selection, x=“Region”, y=“Units_Sold”,
color_discrete_sequence=[“#0083B8”]* len(Region))

left_column, right_column = st.columns(2)
left_column.plotly_chart(bar_chart, use_container_width=True)
right_column.plotly_chart(fig_Product_sales, use_container_width=True)

Pie_chart= px.pie(df_selection, title=‘Price per Unit’, values=‘Units_Sold’, color_discrete_sequence=[“#0083B8”], names=‘Product’)
Regional_sales =px.pie(df_selection, title=‘Sale Region Wise’, values=‘Total_Sales’, color_discrete_sequence=[“#0083B8”], names=‘Region’)

right_column, left_column= st.columns(2)
right_column.plotly_chart(Pie_chart, use_container_width=True)
left_column.plotly_chart(Regional_sales, use_container_width=True)

Histo = px.histogram(df, x=“Price per Unit”, nbins=20)
Store_sales =px.pie(df_selection, title=‘Sale Store Wise’, values=‘Total_Sales’, color_discrete_sequence=[“#0083B8”],names=‘Sales_Method’)

right_column, left_column= st.columns(2)
left_column.plotly_chart( Histo,use_container_width=True)
right_column.plotly_chart( Store_sales,use_container_width=True)

df2=df_selection.copy()

df2[‘Region’]=pd.factorize(df2.Region)[0]
df2[‘State’]=pd.factorize(df2.State)[0]
df2[‘City’]=pd.factorize(df2.City)[0]
df2[‘Product’]=pd.factorize(df2.Product)[0]
df2[‘Retailer’]=pd.factorize(df2.Retailer)[0]

df2.rename(columns = {‘Sales_Method’:‘Method’}, inplace = True)
df2[‘Method’]=pd.factorize(df2.Method)[0]
df2 = df2.drop(‘Retailer ID’,axis=1)
df2 = df2.drop(‘Invoice Date’,axis=1)
df2.head()

corr=df2.corr()
print(corr)

fig = px.imshow(df2.corr())
st.write(fig, use_container_width=True)

hide_st_style = “”"

#mainMenu {Visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}

“”"

st.markdown(hide_st_style, unsafe_allow_html=True)

Please show us your requirements.txt file or even better, provide a link to your public github repo.
As the error message suggests, you probably forgot to add the optional pandas dependency openpyxl in this file.

2 Likes

this is my requirements.txt

(Attachment requirements.txt is missing)

I have the same problem. What was the solution then?

in my case i am using excel file (xlsx) of datasets after changing the data set into csv, its working

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.