Exemple #1
0
def multiview_server(
    server: Type[_S],
    host: str,
    port: int,
    server_options: Optional[Any] = None,
    run_options: Optional[Dict[str, Any]] = None,
    app: Optional[Any] = None,
) -> Tuple[MultiViewMount, _S]:
    """Set up a server where views can be dynamically added.

    In other words this allows the user to work with IDOM in an imperative manner.
    Under the hood this uses the :func:`idom.widgets.common.multiview` function to
    add the views on the fly.

    Parameters:
        server: The server type to start up as a daemon
        host: The server hostname
        port: The server port number
        server_options: Value passed to :meth:`AbstractRenderServer.configure`
        run_options: Keyword args passed to :meth:`AbstractRenderServer.daemon`
        app: Optionally provide a prexisting application to register to

    Returns:
        The server instance and a function for adding views.
        See :func:`idom.widgets.common.multiview` for details.
    """
    mount, element = multiview()
    server_instance = server(element)
    server_instance.configure(server_options)
    if app is not None:
        server_instance.register(app)
    server_instance.daemon(host, port, **(run_options or {}))
    return mount, server_instance
Exemple #2
0
def multiview_server(
    server_type: Type[_S],
    host: str = "127.0.0.1",
    port: Optional[int] = None,
    server_config: Optional[Any] = None,
    run_kwargs: Optional[Dict[str, Any]] = None,
    app: Optional[Any] = None,
) -> Tuple[MultiViewMount, _S]:
    """Set up a server where views can be dynamically added.

    In other words this allows the user to work with IDOM in an imperative manner.
    Under the hood this uses the :func:`idom.widgets.common.multiview` function to
    add the views on the fly.

    Parameters:
        server: The server type to start up as a daemon
        host: The server hostname
        port: The server port number
        server_config: Value passed to :meth:`AbstractRenderServer.configure`
        run_kwargs: Keyword args passed to :meth:`AbstractRenderServer.daemon`
        app: Optionally provide a prexisting application to register to

    Returns:
        The server instance and a function for adding views.
        See :func:`idom.widgets.common.multiview` for details.
    """
    mount, component = multiview()

    server = run(
        component,
        server_type,
        host,
        port,
        server_config=server_config,
        run_kwargs=run_kwargs,
        daemon=True,
        app=app,
    )

    return mount, server
Exemple #3
0
    f"{IDOM_MODEL_SERVER_URL_PREFIX}{IDOM_CLIENT_IMPORT_SOURCE_URL.default}"
)


here = Path(__file__).parent

app = Sanic(__name__)
app.static("/docs", str(here / "build"))


@app.route("/")
async def forward_to_index(request):
    return response.redirect("/docs/index.html")


mount, component = multiview()

examples_dir = here / "source" / "examples"
sys.path.insert(0, str(examples_dir))


original_run = idom.run
try:
    for file in examples_dir.iterdir():
        if not file.is_file() or not file.suffix == ".py" or file.stem.startswith("_"):
            continue

        # Modify the run function so when we exec the file
        # instead of running a server we mount the view.
        idom.run = mount[file.stem]
Exemple #4
0
from idom.widgets.utils import multiview
from idom.client.manage import STATIC_DIR
from idom.server.sanic import PerClientStateServer

app = Sanic(__name__)
app.static("/docs", "./docs/build")
app.static("/favicon.ico", str(STATIC_DIR / "favicon.ico"))


@app.route("/")
async def forward_to_index(request):
    return response.redirect("/docs/index.html")


mount, element = multiview()

here = Path(__file__).parent
widgets = here / "source" / "widgets"
sys.path.insert(0, str(widgets))

for file in widgets.iterdir():
    if not file.is_file() or file.suffix != ".py" or file.stem.startswith("_"):
        continue

    with file.open() as f:
        exec(
            f.read(),
            {
                "display": getattr(mount, file.stem),
                "__file__": str(file),