Skip to content

Commit

Permalink
Use explicit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jul 16, 2022
1 parent 8a71ecc commit dd61811
Show file tree
Hide file tree
Showing 43 changed files with 104 additions and 101 deletions.
5 changes: 0 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedFunction": "none",
"reportWildcardImportFromLibrary": "none"
},
"python.formatting.provider": "black",
"[python]": {
"editor.formatOnSave": true,
Expand Down
4 changes: 2 additions & 2 deletions examples/app_with_plot/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shiny import *
from shiny import App, render, ui

# Import modules for plot rendering
import numpy as np
Expand All @@ -16,7 +16,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.plot(alt="A histogram")
def plot():
Expand Down
7 changes: 3 additions & 4 deletions examples/basic_app/app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_slider("n", "N", 0, 100, 20),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
return f"n*2 is {input.n() * 2}"


# The debug=True causes it to print messages to the console.
app = App(app_ui, server, debug=True)
app = App(app_ui, server)
10 changes: 5 additions & 5 deletions examples/camera/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# it may not work properly on all phones. However, the camera input part should still
# work on most phones.

from shiny import *
from shiny.types import FileInfo, SilentException, ImgData

import skimage
import numpy as np
import skimage
from PIL import Image, ImageOps

from shiny import App, render, ui
from shiny.types import FileInfo, ImgData, SilentException

app_ui = ui.page_fluid(
ui.input_file(
"file",
Expand All @@ -27,7 +27,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.image
async def image() -> ImgData:
Expand Down
2 changes: 1 addition & 1 deletion examples/extra_packages/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shiny import *
from shiny import App, ui

import isodate
import attrs
Expand Down
6 changes: 3 additions & 3 deletions examples/fetch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# download.py file for a wrapper function that can be used to make requests in both
# regular Python and Pyodide. (Note that the function isn't actually used in this app.)

from shiny import *
import pyodide.http
from pprint import pformat
import pyodide.http
from shiny import App, reactive, render, ui

app_ui = ui.page_fluid(
ui.input_selectize(
Expand Down Expand Up @@ -56,7 +56,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
# Weather data API: https://github.com/robertoduessmann/weather-api
@reactive.Calc
def url():
Expand Down
15 changes: 7 additions & 8 deletions examples/file_download/app.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import asyncio
from pathlib import Path
import io
from datetime import date

from shiny import *
from htmltools import *
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
from shiny import App, ui


# A card component wrapper.
def ui_card(title, *args):
return (
div(
ui.div(
{"class": "card mb-4"},
div(title, class_="card-header"),
div({"class": "card-body"}, *args),
ui.div(title, class_="card-header"),
ui.div({"class": "card-body"}, *args),
),
)

Expand All @@ -38,7 +37,7 @@ def ui_card(title, *args):
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@session.download()
def download1():
# This is the simplest case. The implementation simply returns the path to a
Expand Down
6 changes: 3 additions & 3 deletions examples/file_upload/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from math import ceil
from shiny import *
import mimetypes
from math import ceil
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_file("file1", "Choose a file to upload:", multiple=True),
Expand All @@ -9,7 +9,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
MAX_SIZE = 50000

@output
Expand Down
4 changes: 2 additions & 2 deletions examples/input_checkbox/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_checkbox("x", "Checkbox input"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_checkbox_group/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_checkbox_group(
Expand All @@ -8,7 +8,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_date/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_date("x", "Date input"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_date_range/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_date_range("x", "Date range input"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_numeric/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_numeric("x", "Number input", value=100),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_password/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_password("x", "Password input", placeholder="Enter password"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_radio/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_radio_buttons(
Expand All @@ -8,7 +8,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_select/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_select("x", "Select input", {"a": "Choice A", "b": "Choice B"}),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_slider/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_slider("x", "Slider input", min=0, max=20, value=10),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_text/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_text("x", "Text input", placeholder="Enter text"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_text_area/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from shiny import *
from shiny import App, render, ui

app_ui = ui.page_fluid(
ui.input_text_area("x", "Text area input", placeholder="Enter text"),
ui.output_text_verbatim("txt"),
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@output
@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/input_update/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date

from shiny import *
from shiny import App, reactive, ui
from shiny.ui import tags, h2

app_ui = ui.page_fluid(
Expand Down Expand Up @@ -88,7 +88,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@reactive.Effect
def _():
# We'll use these multiple times, so use short var names for
Expand Down
11 changes: 5 additions & 6 deletions examples/insert_ui/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from shiny import *
from htmltools import *
from shiny import App, reactive, render, ui

# For plot rendering
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.panel_sidebar(
h2("Dynamic UI"),
ui.h2("Dynamic UI"),
ui.output_ui("ui"),
ui.input_action_button("btn", "Trigger insert/remove ui"),
),
Expand All @@ -20,7 +19,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
@reactive.Calc
def r():
return input.n() * 2
Expand Down Expand Up @@ -51,7 +50,7 @@ def _():
def _():
btn = input.btn()
if btn % 2 == 1:
ui.insert_ui(tags.p("Thanks for clicking!", id="thanks"), "body")
ui.insert_ui(ui.tags.p("Thanks for clicking!", id="thanks"), "body")
elif btn > 0:
ui.remove_ui("#thanks")

Expand Down
7 changes: 4 additions & 3 deletions examples/ipyleaflet/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ipyleaflet as L
from htmltools import css
from shiny import App, reactive, render, ui
from shinywidgets import output_widget, reactive_read, register_widget
from shiny import App, Inputs, Outputs, Session, reactive, render, ui

import ipyleaflet as L

app_ui = ui.page_fluid(
ui.div(
Expand All @@ -15,7 +16,7 @@
)


def server(input: Inputs, output: Outputs, session: Session):
def server(input, output, session):
# Initialize and display when the session starts (1)
map = L.Map(center=(51.476852, -0.000500), zoom=12, scroll_wheel_zoom=True)
# Add a distance scale
Expand Down
Binary file removed examples/ipywidgets/__pycache__/app.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit dd61811

Please sign in to comment.