{ "cells": [ { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [ { "data": { "text/html": [ "
The server is already running on 8882. It must be shut down first to be restarted.
\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%use plotly\n", "import kotlin.math.*" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", "
\n", "
\n", "

A custom separator

\n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val x1 = (0..100).map { it.toDouble() / 100.0 }\n", "val y1 = x1.map { sin(2.0 * PI * it) }\n", "val y2 = x1.map { cos(2.0 * PI * it) }\n", "\n", "val trace1 = Trace(x1, y1) { name = \"sin\" }\n", "val trace2 = Trace(x1, y2) { name = \"cos\" }\n", "\n", "val fragment = Plotly.fragment { container ->\n", " plot(container = container, config = PlotlyConfig{responsive = true}) {\n", " traces(trace1, trace2)\n", " layout {\n", " title = \"The plot above\"\n", " xaxis.title = \"x axis name\"\n", " yaxis.title = \"y axis name\"\n", " }\n", " }\n", " hr()\n", " h1 { +\"A custom separator\" }\n", " hr()\n", " div {\n", " plot(container = container) {\n", " traces(trace1, trace2)\n", " layout {\n", " title = \"The plot below\"\n", " xaxis.title = \"x axis name\"\n", " yaxis.title = \"y axis name\"\n", " }\n", " }\n", " }\n", "}\n", "fragment" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", "
\n", "
\n" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Plotly.plot {\n", " traces(trace1, trace2)\n", " layout {\n", " title = \"The plot below\"\n", " xaxis.title = \"x axis name\"\n", " yaxis.title = \"y axis name\"\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", "
\n", "
\n" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val x = (0..100).map { it.toDouble() / 100.0 }\n", "val y = x.map { sin(2.0 * PI * it) }\n", "\n", "val trace = Trace(x, y) { name = \"sin\" }\n", "\n", "\n", "val dynamicPlot = Plotly.plot {\n", " traces(trace)\n", " layout {\n", " title = \"Dynamic plot\"\n", " xaxis.title = \"x axis name\"\n", " yaxis.title = \"y axis name\"\n", " }\n", "}\n", "\n", "dynamicPlot" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [], "source": [ "import kotlinx.coroutines.*\n", "\n", "val job = GlobalScope.launch {\n", " var time: Long = 0\n", " while (isActive) {\n", " delay(10)\n", " time += 10\n", " val dynamicY = x.map { sin(2.0 * PI * (it + time.toDouble() / 1000.0)) }\n", " trace.y.set(dynamicY)\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [], "source": [ "job.cancel()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:42+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [], "source": [ "dynamicPlot.layout.xaxis.title = \"крокозябра\"" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2020-07-31T11:43+0300", "start_time": "2020-07-31T11:42+0300" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11:43:00.894 [DefaultDispatcher-worker-2] DEBUG ktor.application - Closed server socket for kscience.plotly.Plot@1822ae52\n", "11:43:00.895 [DefaultDispatcher-worker-6] DEBUG ktor.application - Closed server socket for kscience.plotly.Plot@5ec8af0d\n", "11:43:00.896 [pool-2-thread-1] INFO ktor.application - 101 Switching Protocols: GET - /ws/kscience.plotly.Plot@1822ae52, cancelled\n", "11:43:00.897 [DefaultDispatcher-worker-14] DEBUG ktor.application - Closed server socket for kscience.plotly.Plot@4eefd342\n", "11:43:00.897 [pool-2-thread-2] INFO ktor.application - 101 Switching Protocols: GET - /ws/kscience.plotly.Plot@5ec8af0d, cancelled\n", "11:43:00.898 [pool-2-thread-3] INFO ktor.application - 101 Switching Protocols: GET - /ws/kscience.plotly.Plot@4eefd342, cancelled\n", "11:43:00.905 [DefaultDispatcher-worker-9] ERROR io.ktor.server.cio.HttpServer - Unhandled exception caught for CoroutineName(http-pipeline-writer)\n", "kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[ExperimentalCoroutineDispatcher@1a6cc06[scheduler = DefaultDispatcher@1aa286ac[Pool Size {core = 14, max = 1536}, Worker States {CPU = 7, blocking = 0, parked = 7, dormant = 0, terminated = 0}, running workers queues = [0c, 0c, 0c, 0c, 1c, 0c, 0c], global CPU queue size = 0, global blocking queue size = 0, Control State {created workers= 14, blocking tasks = 0, CPUs acquired = 7}]], Continuation at io.ktor.server.cio.backend.ServerPipelineKt$startServerConnectionPipeline$1$outputsActor$1.invokeSuspend(ServerPipeline.kt:49)@3401b226]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers\n", "\tat kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:93)\n", "\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)\n", "Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation is in unnamed module of loader 'app'; kotlinx.coroutines.DispatchedContinuation is in unnamed module of loader java.net.URLClassLoader @7323f4f)\n", "\tat kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)\n", "\tat kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)\n", "\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)\n", "\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)\n", "\t... 4 common frames omitted\n", "11:43:00.905 [DefaultDispatcher-worker-4] ERROR io.ktor.server.cio.HttpServer - Unhandled exception caught for CoroutineName(http-pipeline-writer)\n", "kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[ExperimentalCoroutineDispatcher@1a6cc06[scheduler = DefaultDispatcher@1aa286ac[Pool Size {core = 14, max = 1536}, Worker States {CPU = 9, blocking = 0, parked = 5, dormant = 0, terminated = 0}, running workers queues = [0c, 1c, 0c, 0c, 0c, 0c, 1c, 0c, 0c], global CPU queue size = 0, global blocking queue size = 0, Control State {created workers= 14, blocking tasks = 0, CPUs acquired = 7}]], Continuation at io.ktor.server.cio.backend.ServerPipelineKt$startServerConnectionPipeline$1$outputsActor$1.invokeSuspend(ServerPipeline.kt:49)@34cb0946]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers\n", "\tat kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:93)\n", "\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)\n" ] }, { "data": { "text/html": [ "
Update server is stopped
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)\n", "\tat kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)\n", "Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation is in unnamed module of loader 'app'; kotlinx.coroutines.DispatchedContinuation is in unnamed module of loader java.net.URLClassLoader @7323f4f)\n", "\tat kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)\n", "\tat kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)\n", "\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)\n", "\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)\n" ] } ], "source": [ "JupyterPlotly.stopUpdates()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "hide_input": false, "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "codemirror_mode": "text/x-kotlin", "file_extension": ".kt", "mimetype": "text/x-kotlin", "name": "kotlin", "pygments_lexer": "kotlin", "version": "1.4.20-dev-2342" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": false, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }