|
47 | 47 | }, |
48 | 48 | { |
49 | 49 | "cell_type": "code", |
50 | | - "execution_count": null, |
| 50 | + "execution_count": 1, |
51 | 51 | "metadata": {}, |
52 | 52 | "outputs": [], |
53 | 53 | "source": [ |
|
65 | 65 | }, |
66 | 66 | { |
67 | 67 | "cell_type": "code", |
68 | | - "execution_count": null, |
69 | | - "metadata": {}, |
70 | | - "outputs": [], |
| 68 | + "execution_count": 2, |
| 69 | + "metadata": {}, |
| 70 | + "outputs": [ |
| 71 | + { |
| 72 | + "name": "stdout", |
| 73 | + "output_type": "stream", |
| 74 | + "text": [ |
| 75 | + "[2020-04-22 17:37:27 -0700] [3083] [INFO] Goin' Fast @ http://127.0.0.1:8765\n" |
| 76 | + ] |
| 77 | + } |
| 78 | + ], |
71 | 79 | "source": [ |
72 | 80 | "from idom.server.sanic import PerClientState\n", |
73 | | - "from example_utils import (\n", |
74 | | - " example_uri_root,\n", |
75 | | - " HtmlLink,\n", |
76 | | - " pretty_dict_string,\n", |
77 | | - " is_on_jupyterhub,\n", |
78 | | - ")\n", |
79 | | - "\n", |
80 | | - "webpage_url = HtmlLink(example_uri_root(\"http\", 8765))\n", |
81 | | - "\n", |
82 | | - "mount, element = idom.hotswap()\n", |
83 | | - "PerClientState(element).configure({\"cors\": not is_on_jupyterhub()}).daemon(\n", |
84 | | - " \"127.0.0.1\", 8765, access_log=False\n", |
85 | | - ")\n", |
| 81 | + "from example_utils import setup_example_server, display_href, pretty_dict_string\n", |
86 | 82 | "\n", |
| 83 | + "server_url, server, mount = setup_example_server(PerClientState, \"127.0.0.1\", 8765)\n", |
87 | 84 | "\n", |
88 | | - "def display(*args, **kwargs):\n", |
89 | | - " element, *args = args\n", |
| 85 | + "def display(element, *args, **kwargs):\n", |
90 | 86 | " mount(element, *args, **kwargs)\n", |
91 | | - " return idom.display(\"jupyter\", str(webpage_url), secure=is_on_jupyterhub())" |
| 87 | + " return idom.display(\"jupyter\", server_url)" |
92 | 88 | ] |
93 | 89 | }, |
94 | 90 | { |
|
102 | 98 | }, |
103 | 99 | { |
104 | 100 | "cell_type": "code", |
105 | | - "execution_count": null, |
| 101 | + "execution_count": 3, |
106 | 102 | "metadata": {}, |
107 | 103 | "outputs": [], |
108 | 104 | "source": [ |
|
127 | 123 | }, |
128 | 124 | { |
129 | 125 | "cell_type": "code", |
130 | | - "execution_count": null, |
131 | | - "metadata": {}, |
132 | | - "outputs": [], |
| 126 | + "execution_count": 4, |
| 127 | + "metadata": {}, |
| 128 | + "outputs": [ |
| 129 | + { |
| 130 | + "name": "stdout", |
| 131 | + "output_type": "stream", |
| 132 | + "text": [ |
| 133 | + "Try clicking the image! 🖱️\n" |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
| 137 | + "data": { |
| 138 | + "text/html": [ |
| 139 | + "<script>document.idomServerExists = true;</script>" |
| 140 | + ] |
| 141 | + }, |
| 142 | + "metadata": {}, |
| 143 | + "output_type": "display_data" |
| 144 | + }, |
| 145 | + { |
| 146 | + "data": { |
| 147 | + "text/html": [ |
| 148 | + "\n", |
| 149 | + " <div id=\"idom-2dbb91f1d1c948adab63c95854c5b9db\" class=\"idom-widget\"/>\n", |
| 150 | + " \n", |
| 151 | + " <script type=\"module\">\n", |
| 152 | + " // we want to avoid making this request (in case of CORS)\n", |
| 153 | + " // unless we know an IDOM server is expected to respond\n", |
| 154 | + " if (document.idomServerExists) {\n", |
| 155 | + " const loc = {\"host\": \"127.0.0.1:8765\", \"protocol\": \"http:\"};\n", |
| 156 | + " const idom_url = \"//\" + loc.host + \"\";\n", |
| 157 | + " const http_proto = loc.protocol;\n", |
| 158 | + " const ws_proto = (http_proto === \"https:\") ? \"wss:\" : \"ws:\";\n", |
| 159 | + " import(http_proto + idom_url + \"/client/core_modules/layout.js\").then(\n", |
| 160 | + " (module) => {\n", |
| 161 | + " module.renderLayout(\n", |
| 162 | + " document.getElementById(\"idom-2dbb91f1d1c948adab63c95854c5b9db\"),\n", |
| 163 | + " ws_proto + idom_url + \"/stream\"\n", |
| 164 | + " );\n", |
| 165 | + " }\n", |
| 166 | + " );\n", |
| 167 | + " }\n", |
| 168 | + " </script>\n", |
| 169 | + " \n", |
| 170 | + " " |
| 171 | + ], |
| 172 | + "text/plain": [ |
| 173 | + "JupyterWigdet('')" |
| 174 | + ] |
| 175 | + }, |
| 176 | + "execution_count": 4, |
| 177 | + "metadata": {}, |
| 178 | + "output_type": "execute_result" |
| 179 | + } |
| 180 | + ], |
133 | 181 | "source": [ |
134 | 182 | "print(\"Try clicking the image! 🖱️\")\n", |
135 | 183 | "\n", |
|
151 | 199 | "metadata": {}, |
152 | 200 | "outputs": [], |
153 | 201 | "source": [ |
154 | | - "webpage_url" |
| 202 | + "display_href(server_url)" |
155 | 203 | ] |
156 | 204 | }, |
157 | 205 | { |
|
770 | 818 | "outputs": [], |
771 | 819 | "source": [ |
772 | 820 | "from idom.server.sanic import SharedClientState\n", |
| 821 | + "from example_utils import setup_example_server, display_href, pretty_dict_string\n", |
773 | 822 | "\n", |
774 | | - "shared_webpage_url = HtmlLink(example_uri_root(\"http\", 5678))\n", |
775 | | - "\n", |
776 | | - "mount_shared, element = idom.hotswap()\n", |
777 | | - "SharedClientState(element).configure({\"cors\": not is_on_jupyterhub()}).daemon(\n", |
778 | | - " \"127.0.0.1\", 5678, access_log=False\n", |
779 | | - ")\n", |
780 | | - "\n", |
| 823 | + "shared_server_url, shared_server, mount_shared = setup_example_server(SharedClientState, \"127.0.0.1\", 5678)\n", |
781 | 824 | "\n", |
782 | | - "def shared_display(*args, **kwargs):\n", |
783 | | - " element, *args = args\n", |
| 825 | + "def display_shared(element, *args, **kwargs):\n", |
784 | 826 | " mount_shared(element, *args, **kwargs)\n", |
785 | | - " return idom.display(\"jupyter\", str(shared_webpage_url), secure=is_on_jupyterhub())" |
| 827 | + " return idom.display(\"jupyter\", shared_server_url)" |
786 | 828 | ] |
787 | 829 | }, |
788 | 830 | { |
|
798 | 840 | "metadata": {}, |
799 | 841 | "outputs": [], |
800 | 842 | "source": [ |
801 | | - "display = shared_display(DragDropBoxes)" |
| 843 | + "display = display_shared(DragDropBoxes)" |
802 | 844 | ] |
803 | 845 | }, |
804 | 846 | { |
|
0 commit comments