File size: 1,465 Bytes
1b575c8 |
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 |
from shiny import render, reactive, ui
import pandas as pd
import matplotlib.pyplot as plt
def create_server():
def server(input, output, session):
# Update dropdowns when file is uploaded
@reactive.Effect
def _():
file = input.file()
if file is not None:
# Read the uploaded file
df = pd.read_csv(file[0]['datapath'])
choices = list(df.columns)
ui.update_select("var1", choices=choices, session=session)
ui.update_select("var2", choices=choices, session=session)
# Render the data table
@output
@render.table
def table():
file = input.file()
if file is None:
return None
return pd.read_csv(file[0]['datapath'])
# Render the plot
@output
@render.plot
def plot():
file = input.file()
if file is None:
return None
df = pd.read_csv(file[0]['datapath'])
# Create matplotlib scatter plot
plt.figure(figsize=(10, 6))
plt.scatter(df[input.var1()], df[input.var2()])
plt.xlabel(input.var1())
plt.ylabel(input.var2())
plt.title(input.plot_title())
return plt.gcf()
return server |