Spaces:
Running
Running
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from shiny import App, ui, render | |
| app_ui = ui.page_fluid( | |
| ui.layout_sidebar( | |
| ui.panel_sidebar( | |
| ui.input_file("file", "Choose a file to upload:", multiple=False), | |
| ui.input_slider("slider", "Choose position:", min=0, max=1, step=0.01, value=0.5), | |
| ui.input_switch("switch", "Vertikal - Horizontal:", value=True), | |
| ui.input_switch("switch2", "Links - Rechts:", value=True), | |
| ), | |
| ui.panel_main( | |
| ui.output_plot("plot"), | |
| ui.output_plot("mirror") | |
| ) | |
| ) | |
| ) | |
| def server(input, output, session): | |
| def plot(): | |
| # print(input.file()) | |
| if input.file() is not None: | |
| img = plt.imread(input.file()[0]['datapath']) | |
| # print(img) | |
| plt.imshow(img) | |
| # draw a vertical line at x = 0 that spans the yrange | |
| if input.switch(): | |
| plt.axvline(input.slider() * img.shape[1], color="black", linestyle="--") | |
| else: | |
| plt.axhline(input.slider() * img.shape[0], color="black", linestyle="--") | |
| def mirror(): | |
| if input.file() is not None: | |
| img = plt.imread(input.file()[0]['datapath']) | |
| if input.switch(): | |
| if input.switch2(): | |
| orig = img[:, :int(input.slider() * img.shape[1])] | |
| temp = np.fliplr(orig) | |
| img = np.concatenate((orig, temp), axis=1) | |
| else: | |
| orig = img[:, int(input.slider() * img.shape[1]):] | |
| temp = np.fliplr(orig) | |
| img = np.concatenate((temp, orig), axis=1) | |
| else: | |
| if input.switch2(): | |
| orig = img[:int(input.slider() * img.shape[0]), :] | |
| temp = np.flipud(orig) | |
| img = np.concatenate((orig, temp), axis=0) | |
| else: | |
| orig = img[int(input.slider() * img.shape[0]):, :] | |
| temp = np.flipud(orig) | |
| img = np.concatenate((temp, orig), axis=0) | |
| fig, ax = plt.subplots(1) | |
| ax.axis('off') | |
| fig.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0) | |
| ax.imshow(img) | |
| app = App(app_ui, server) | |