-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (51 loc) · 1.96 KB
/
app.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import io
from typing import List
import shinyswatch
from shiny import App, reactive, render, ui
import conversion_calculator
app_ui = ui.page_fluid(
shinyswatch.theme.superhero(),
ui.download_button("download_template", "Download Template"),
ui.input_file("file1", "Choose a file to upload for conversion:", multiple=True),
ui.output_table("file_content"),
ui.download_button("download_conversion", "Download Conversion"),
)
def server(input, output, session):
MAX_SIZE = 50000
@session.download(filename="template.csv")
def download_template():
return conversion_calculator.lib.get_csv_template_path()
@output
@render.table
def file_content():
file_infos = input.file1()
if not file_infos:
return
if len(file_infos) > 1:
return
return conversion_calculator.lib.parse_input_csv(file_infos[0]["datapath"])
# the following, from here to the end of the server function, doesn't work; it's the part of this which actually does the conversion
@reactive.Calc
def run_conversion():
file_infos = input.file1()
return conversion_calculator.lib.convert_spreadsheet(
conversion_calculator.lib.parse_input_csv(file_infos[0]["datapath"])
)
@session.download(filename="converted.csv")
def download_conversion():
file_infos = input.file1()
if not file_infos:
return
if len(file_infos) > 1:
return
try:
# input_df = conversion_calculator.lib.parse_input_csv(file_infos[0]['datapath'])
# converted_df = conversion_calculator.lib.convert_spreadsheet(input_df)
return io.BytesIO(
conversion_calculator.lib.dataframe_to_csv(run_conversion()).encode(
"utf-8"
)
)
except Exception as e:
return io.BytesIO(str(e).encode("utf-8"))
app = App(app_ui, server)