File size: 1,883 Bytes
96b1be4
 
001a9c1
96b1be4
 
001a9c1
96b1be4
001a9c1
96b1be4
 
 
 
001a9c1
96b1be4
 
 
 
001a9c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96b1be4
001a9c1
 
96b1be4
9cbb15c
96b1be4
001a9c1
96b1be4
9cbb15c
96b1be4
001a9c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
import pandas as pd
import plotly.express as px

# Title of the App
st.title("Smart Data Visualization App")

# File Upload Section
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"])

if uploaded_file:
    try:
        # Load the Excel file into a DataFrame
        df = pd.read_excel(uploaded_file)
        st.write("Data Preview:")
        st.dataframe(df)

        # User selects columns to visualize
        x_axis = st.selectbox("Select X-axis column", df.columns)
        y_axis = st.multiselect("Select Y-axis column(s)", [col for col in df.columns if col != x_axis])

        if x_axis and y_axis:
            # Determine the best type of graph
            if df[x_axis].nunique() < len(df[x_axis]) * 0.5:
                # If the X-axis is categorical, choose a bar chart
                chart_type = "Bar Chart"
                fig = px.bar(df, x=x_axis, y=y_axis, barmode="group")
            elif len(y_axis) == 1:
                # For single numerical column, plot a line chart
                chart_type = "Line Chart"
                fig = px.line(df, x=x_axis, y=y_axis[0])
            else:
                # If multiple numerical columns are selected, use a scatter plot matrix
                chart_type = "Scatter Matrix"
                fig = px.scatter_matrix(df, dimensions=y_axis, color=x_axis)

            # Display the selected chart type and plot
            st.write(f"Automatically Selected Chart Type: {chart_type}")
            st.plotly_chart(fig)
        else:
            st.info("Please select columns for the X and Y axes to visualize.")
    except Exception as e:
        st.error(f"Error processing the file: {e}")
else:
    st.info("Upload an Excel file to get started.")

# Footer
st.write("---")
st.write("Powered by [Streamlit](https://streamlit.io) and [Plotly](https://plotly.com).")