aagoluoglu commited on
Commit
5f00534
·
1 Parent(s): e7cace3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -119
app.py CHANGED
@@ -22,36 +22,12 @@ sns.set_theme()
22
  dir = Path(__file__).resolve().parent
23
  www_dir = Path(__file__).parent.resolve() / "www"
24
 
25
- df = pd.read_csv(Path(__file__).parent / "penguins.csv", na_values="NA")
26
- numeric_cols: List[str] = df.select_dtypes(include=["float64"]).columns.tolist()
27
- species: List[str] = df["Species"].unique().tolist()
28
- species.sort()
29
-
30
  ### UI ###
31
  app_ui = ui.page_fillable(
32
  shinyswatch.theme.minty(),
33
  ui.layout_sidebar(
34
  ui.sidebar(
35
  ui.input_file("tile_image", "Choose an Image", accept=[".tif", ".tiff", ".png"], multiple=False),
36
- # Artwork by @allison_horst
37
- ui.input_selectize(
38
- "xvar",
39
- "X variable",
40
- numeric_cols,
41
- selected="Bill Length (mm)",
42
- ),
43
- ui.input_selectize(
44
- "yvar",
45
- "Y variable",
46
- numeric_cols,
47
- selected="Bill Depth (mm)",
48
- ),
49
- ui.input_checkbox_group(
50
- "species", "Filter by species", species, selected=species
51
- ),
52
- ui.hr(),
53
- ui.input_switch("by_species", "Show species", value=True),
54
- ui.input_switch("show_margins", "Show marginal plots", value=True),
55
  ),
56
  #ui.output_image("uploaded_image"), # display the uploaded sidewalk tile image, for some reason doesn't work on all accepted files
57
  ui.output_plot("prediction_plots", fill=True),
@@ -273,101 +249,6 @@ def server(input: Inputs, output: Outputs, session: Session):
273
  plt.tight_layout()
274
 
275
  return fig
276
-
277
-
278
-
279
-
280
-
281
-
282
- @reactive.Calc
283
- def filtered_df() -> pd.DataFrame:
284
- """Returns a Pandas data frame that includes only the desired rows"""
285
-
286
- # This calculation "req"uires that at least one species is selected
287
- req(len(input.species()) > 0)
288
-
289
- # Filter the rows so we only include the desired species
290
- return df[df["Species"].isin(input.species())]
291
-
292
- @output
293
- @render.plot
294
- def scatter():
295
- """Generates a plot for Shiny to display to the user"""
296
-
297
- # The plotting function to use depends on whether margins are desired
298
- plotfunc = sns.jointplot if input.show_margins() else sns.scatterplot
299
-
300
- plotfunc(
301
- data=filtered_df(),
302
- x=input.xvar(),
303
- y=input.yvar(),
304
- palette=palette,
305
- hue="Species" if input.by_species() else None,
306
- hue_order=species,
307
- legend=False,
308
- )
309
-
310
- @output
311
- @render.ui
312
- def value_boxes():
313
- df = filtered_df()
314
-
315
- def penguin_value_box(title: str, count: int, bgcol: str, showcase_img: str):
316
- return ui.value_box(
317
- title,
318
- count,
319
- {"class_": "pt-1 pb-0"},
320
- showcase=ui.fill.as_fill_item(
321
- ui.tags.img(
322
- {"style": "object-fit:contain;"},
323
- src=showcase_img,
324
- )
325
- ),
326
- theme_color=None,
327
- style=f"background-color: {bgcol};",
328
- )
329
-
330
- if not input.by_species():
331
- return penguin_value_box(
332
- "Penguins",
333
- len(df.index),
334
- bg_palette["default"],
335
- # Artwork by @allison_horst
336
- showcase_img="penguins.png",
337
- )
338
-
339
- value_boxes = [
340
- penguin_value_box(
341
- name,
342
- len(df[df["Species"] == name]),
343
- bg_palette[name],
344
- # Artwork by @allison_horst
345
- showcase_img=f"{name}.png",
346
- )
347
- for name in species
348
- # Only include boxes for _selected_ species
349
- if name in input.species()
350
- ]
351
-
352
- return ui.layout_column_wrap(*value_boxes, width = 1 / len(value_boxes))
353
-
354
-
355
- # "darkorange", "purple", "cyan4"
356
- colors = [[255, 140, 0], [160, 32, 240], [0, 139, 139]]
357
- colors = [(r / 255.0, g / 255.0, b / 255.0) for r, g, b in colors]
358
-
359
- palette: Dict[str, Tuple[float, float, float]] = {
360
- "Adelie": colors[0],
361
- "Chinstrap": colors[1],
362
- "Gentoo": colors[2],
363
- "default": sns.color_palette()[0], # type: ignore
364
- }
365
-
366
- bg_palette = {}
367
- # Use `sns.set_style("whitegrid")` to help find approx alpha value
368
- for name, col in palette.items():
369
- # Adjusted n_colors until `axe` accessibility did not complain about color contrast
370
- bg_palette[name] = mpl_colors.to_hex(sns.light_palette(col, n_colors=7)[1]) # type: ignore
371
 
372
 
373
  app = App(
 
22
  dir = Path(__file__).resolve().parent
23
  www_dir = Path(__file__).parent.resolve() / "www"
24
 
 
 
 
 
 
25
  ### UI ###
26
  app_ui = ui.page_fillable(
27
  shinyswatch.theme.minty(),
28
  ui.layout_sidebar(
29
  ui.sidebar(
30
  ui.input_file("tile_image", "Choose an Image", accept=[".tif", ".tiff", ".png"], multiple=False),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ),
32
  #ui.output_image("uploaded_image"), # display the uploaded sidewalk tile image, for some reason doesn't work on all accepted files
33
  ui.output_plot("prediction_plots", fill=True),
 
249
  plt.tight_layout()
250
 
251
  return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
 
254
  app = App(