-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
45 lines (37 loc) · 1.07 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
from shiny import ui, render, reactive, req, App
import shinyswatch
import pandas as pd
# Define UI
app_ui = ui.page_fluid(
# Apply theme
shinyswatch.theme.flatly(),
# App title
ui.h1("CSV File Uploader"),
# Sidebar layout with input and output definitions
ui.layout_sidebar(
ui.sidebar(
ui.input_file("data_file", "Choose CSV File", accept=[".csv"], multiple=False),
ui.input_checkbox("header", "Header", value = True),
open = "always"
),
# Show CSV data
ui.output_table("file_contents"),
)
)
# Define server logic
def server(input, output, session):
# Read CSV file
@reactive.calc
def file_data():
req(input.data_file())
data_file_infos = input.data_file()
df = pd.read_csv(
data_file_infos[0]["datapath"],
header = 'infer' if input.header() == True else None )
return df
# Show CSV data
@render.table
def file_contents():
return file_data()
# Run the application
app = App(app_ui, server)