|
from shiny import render, reactive, ui
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
def create_server():
|
|
def server(input, output, session):
|
|
|
|
@reactive.Effect
|
|
def _():
|
|
file = input.file()
|
|
if file is not None:
|
|
|
|
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)
|
|
|
|
|
|
@output
|
|
@render.table
|
|
def table():
|
|
file = input.file()
|
|
if file is None:
|
|
return None
|
|
return pd.read_csv(file[0]['datapath'])
|
|
|
|
|
|
@output
|
|
@render.plot
|
|
def plot():
|
|
file = input.file()
|
|
if file is None:
|
|
return None
|
|
|
|
df = pd.read_csv(file[0]['datapath'])
|
|
|
|
|
|
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 |