<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Taieb on Medium]]></title>
        <description><![CDATA[Stories by David Taieb on Medium]]></description>
        <link>https://medium.com/@DTAIEB55?source=rss-23afa685a28e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SmggCaJnoI-Um4-w.jpg</url>
            <title>Stories by David Taieb on Medium</title>
            <link>https://medium.com/@DTAIEB55?source=rss-23afa685a28e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:57:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DTAIEB55/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Visual Python Debugger for Jupyter Notebooks You’ve Always Wanted]]></title>
            <link>https://medium.com/codait/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/761713babc62</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[jupyter]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pixiedust]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Fri, 09 Mar 2018 19:37:17 GMT</pubDate>
            <atom:updated>2018-09-27T01:13:08.858Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing PixieDebugger</h4><p>I’ve been using Jupyter Notebooks with great delight for many years now, mostly with Python, and it’s validating to see that their popularity keeps growing, both in academia and the industry. I do have a pet peeve though, which is the lack of a first-class visual debugger similar to these available in other IDEs like Eclipse, IntelliJ, or Visual Studio Code.</p><p>Some would rightfully point out that Jupyter already supports <a href="https://docs.python.org/2/library/pdb.html">pdb</a> for simple debugging, where you can manually and sequentially enter commands to do things like inspect variables, set breakpoints, etc. — and this is probably sufficient when it comes to debugging simple analytics. To raise the bar, the PixieDust team is happy to introduce the first (to the best of our knowledge) visual Python debugger for Jupyter Notebooks.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZ-tPeEkVqjk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZ-tPeEkVqjk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZ-tPeEkVqjk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e07f1caaf5a8ad920558b084fce2c526/href">https://medium.com/media/e07f1caaf5a8ad920558b084fce2c526/href</a></iframe><blockquote><strong><em>Editor’s note:</em></strong> PixieDebugger currently only works with classic Jupyter Notebooks; JupyterLab is not yet supported.</blockquote><h3>Introducing PixieDebugger</h3><p>As advertised, the PixieDebugger is a visual Python debugger built as a <a href="https://ibm-watson-data-lab.github.io/pixiedust/pixieapps.html">PixieApp</a>, and includes a source editor, local variable inspector, console output, the ability to evaluate Python expressions in the current context, breakpoints management, and a toolbar for controlling code execution.</p><p>To invoke the PixieDebugger for a specific cell, simply add the <strong>%%pixie_debugger</strong> magic at the top of the cell and run it.</p><p>As an example, let’s consider the following sample code that finds the max value in an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56913996b9d5d2650c562914e3b1dee1/href">https://medium.com/media/56913996b9d5d2650c562914e3b1dee1/href</a></iframe><blockquote><strong><em>Note:</em></strong> As a prerequisite, install PixieDust using the following pip command: pip install pixiedust. You’ll also need to import it into its own cell: import pixiedust.</blockquote><p>When running the cell, the PixieDebugger will automatically be invoked to break at the first executable line of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZCMTpuFwGAJDcx0OIeE0A.png" /><figcaption>PixieDebugger in action</figcaption></figure><p>Some details to note:</p><ul><li>The toolbar on the top left lets you control the execution flow of your code: resume execution, step over, step into, step out, move current frame one up and one down.</li><li>The source editor shows the current code and highlights the current line being executed. The gutter on the left shows the line numbers and an icon for each line that has a breakpoint installed.</li><li>The variables panel on the right automatically shows the local variables for the current context.</li><li>The console tab shows any output from the current program or the PixieDebugger.</li><li>The Evaluate tab allows you to enter any Python expression and run it to get its value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dHMVklW5uRj8SdqjpZj3iA.png" /><figcaption>Evaluate pane of the PixieDebugger</figcaption></figure><ul><li>The Breakpoints tab displays the list of active breakpoints and lets you add a new one. When you add a new breakpoint, an icon is automatically added to the corresponding line.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*Pmk4rvJFWrNBMgJxnvPlZw.png" /><figcaption>Setting breakpoints</figcaption></figure><p>There’s also a “run to line” feature, where you can run only a portion of code. You can directly run to a specific line of code by hovering over a line number on the gutter to make the icon appear and clicking it to move the code execution to the targeted line. This can be useful when you have a for loop, and don’t want to step into each part of the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtrGiSRXMupizdRXk8MEBQ.png" /><figcaption>PixieDebugger “run to line” feature</figcaption></figure><p>Another optimization you might want to use is the ability to set breakpoints as a directive of the %%pixie_debugger magic, by using the -b argument switch, and specify a list of breakpoints separated by a space. The breakpoints can be either a method name or a line number.</p><p>Using our previous example, let’s run the PixieDebugger with 2 breakpoints: one stopping at method find_max and the other at line 9.</p><blockquote><strong><em>Note:</em></strong> Line 9 corresponds to line 7 in the original cell’s code. This is because the PixieDebugger is adding a few lines when running it. You should always use the line number shown in the PixieDebugger editor.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da651714e0ab211eba3c2566b7ac9584/href">https://medium.com/media/da651714e0ab211eba3c2566b7ac9584/href</a></iframe><p>The code will now automatically stop at the first breakpoint we’ve set in the magic arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHFdz5ygszPMVYInkDrNiA.png" /><figcaption>Setting breakpoints in the PixieDebugger</figcaption></figure><p>Invoking the PixieDebugger post-mortem (after an exception has happened) is also possible with the line magic %pixie_debugger. (Notice the difference between the <em>cell</em> magic, which has two % symbols, and the <em>line</em> magic, which has only one and no argument.) This is useful to troubleshoot hard-to-reproduce errors.</p><p>The following sample code simulates a ZeroDivisionError exception. We then call %pixie_debugger in a separate cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*neCV-jBrj28sD8yad3qE0w.png" /><figcaption>Post-Mortem debugging after an exception occurred</figcaption></figure><blockquote><strong><em>Note:</em></strong> When in the debugger, the main thread in the kernel is suspended; therefore, no other code can be executed until the debugging session is done. You will know that it’s safe to execute other cells when the “kernel busy” indicator on the top right of the Notebook page is back to idle.</blockquote><h3>Using the PixieDebugger to debug PixieApp routes</h3><p>Where it becomes even more interesting is that the PixieDebugger also works to debug <a href="https://pixiedust.github.io/pixiedust/">PixieApps</a>. To illustrate how it works, let’s take an example of a simple PixieApp that has one button that calls a route called <strong>bad_route</strong> to populate a div element. In turn, the bad_route implementation calls <strong>bad_method</strong>, which triggers a ZeroDivisionError exception.</p><p>To debug bad_route, we simply use the <strong>debug_route</strong> keyword argument with the value “bad_route”. This will trigger the debugger when bad_route is invoked upon clicking the button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05f01aba0d855c2122190d68f564d906/href">https://medium.com/media/05f01aba0d855c2122190d68f564d906/href</a></iframe><p>Let’s run this cell and see how the PixieDebugger is triggered when bad_route is invoked. What’s more, the PixieDebugger is actually displayed in the target div the route is supposed to populate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9w8i3AcO3s1rJovd3NWdZg.png" /><figcaption>PixieDebugger invoked to debug a PixieApp route</figcaption></figure><p>In case you didn’t specify a route to be debugged and an exception occurs, the PixieApp framework now provides an enhanced traceback with two extra buttons:</p><ul><li>Post-Mortem: Invoke the debugger to do a post-mortem troubleshooting session.</li><li>Debug Route: While post-mortem is only used to inspect local variables, you can use the debug route button to replay the route, stopping at the first executable statement.</li></ul><p>Here’s what the new traceback looks like with the sample PixieApp above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OPCqJh3Ei_YwG5I-c9p-MA.png" /><figcaption>Enhanced traceback for PixieApp with debugging facilities</figcaption></figure><h3><strong>Bugging out</strong></h3><p>The new PixieDebugger feature provides a long-awaited visual Python debugger to the Jupyter Notebook ecosystem, which takes data science notebooks one step closer to becoming a true IDE for both data scientists and developers.</p><p>The first version will be available starting in PixieDust 1.1.8, and I hope you will give it a try. As always, we look forward to your feedback on how to improve it, either by contributing a pull request or creating issues on the <a href="https://github.com/ibm-watson-data-lab/pixiedust">PixieDust GitHub Repo</a>.</p><p>From the PixieDust team: Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=761713babc62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62">The Visual Python Debugger for Jupyter Notebooks You’ve Always Wanted</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Share Your Jupyter Notebook Charts on the Web]]></title>
            <link>https://medium.com/codait/share-your-jupyter-notebook-charts-on-the-web-43e190df4adb?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/43e190df4adb</guid>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[pixiedust]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Fri, 20 Oct 2017 17:50:59 GMT</pubDate>
            <atom:updated>2017-10-20T17:50:59.956Z</atom:updated>
            <content:encoded><![CDATA[<h4>PixieDust now lets you turn charts into standalone web pages</h4><p>In my<a href="https://medium.com/ibm-watson-data-lab/deploy-your-analytics-as-web-apps-using-pixiedusts-1-1-release-d08067584a14"> last blog post</a>, I talked about effortless operationalization of data science with the new PixieGateway server — part of PixieDust — that lets you deploy Jupyter Notebook PixieApps as standalone web apps.</p><p>Starting with PixieDust 1.1.1, the PixieGateway server now supports sharing of charts created with the display() function, effectively turning them into standalone web pages. This new feature is extremely attractive because there is absolutely no coding necessary.</p><p>Simply use the interactive PixieDust display() function from within a Jupyter Notebook to build your chart, click on the <strong>Share</strong> button, add an optional description and <em>voila</em>, you get a URL that you can distribute to your team. They can then see the chart without needing to run a Jupyter Notebook. All they need is a web browser.</p><blockquote><strong>Note:</strong> PixieGateway is still in alpha. Much like the ability to publish PixieApps as interactive web apps (<a href="https://ibm-watson-data-lab.github.io/pixiedust/1-1.html">release 1.1</a>), the ability to publish charts as web pages (<a href="https://ibm-watson-data-lab.github.io/pixiedust/1-1-1.html">release 1.1.1</a>) also uses the PixieGateway server. Thus, this feature is still in alpha and therefore not ready to be used in production.</blockquote><h3><strong>Chart sharing in action</strong></h3><p>Using display() to create a chart, you’ll now see a <strong>Share</strong> button next to “Options”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*nzEmkgQm1UtFNHQVKPc3fQ.png" /><figcaption>The share button is available on all charts.</figcaption></figure><p>The Share dialog will ask for the following information:</p><ol><li><strong>PixieGateway server:</strong> If you don’t have one, see <a href="https://medium.com/ibm-watson-data-lab/deploy-your-analytics-as-web-apps-using-pixiedusts-1-1-release-d08067584a14">this blog post</a> for instructions on how to set one up.</li><li><strong>Description:</strong> Optional free-form text explaining what the chart is about. It will be added to the standalone webpage.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*ccirJD8O4_T86qE_uIb3CA.png" /><figcaption>Get ready to create your chart webpage.</figcaption></figure><p>Click <strong>Share,</strong> and if all goes well, you should get a URL for your chart webpage that is ready to share:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*2OgkqHUx_qJoxi8PhDhkfQ.png" /><figcaption>Copy the URL and start distributing to your team.</figcaption></figure><p>You can copy the URL and/or click on the link to go directly to the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*0fBoI_qXGTAYf8sV1yiyUQ.png" /><figcaption>What a beautiful chart!</figcaption></figure><h3><strong>Improving this feature</strong></h3><p>We have multiple ideas on how to improve this feature:</p><ol><li><strong>Security:</strong> Password-protect your charts.</li><li><strong>Embed:</strong> Provide embed code so you can include the chart in your own websites (similar to YouTube).</li><li><strong>Auto-refresh:</strong> Schedule automatic refresh of charts, with options like “Refresh every x hour” or “Every day at 10 p.m.”</li></ol><p>This last idea would be a useful feature if the data source used to build the chart were to change over time (e.g., sales data). In this case, the chart would become live without the need for you to re-run the notebook. Even better, you could add a live chart to your website if you were to combine it with the embed feature proposed above.</p><p>As always, we need your feedback and ideas to make PixieGateway server better. If you like this feature and, like me, think that it will help unlock the value of data science beyond Jupyter Notebooks, then join the conversation on <a href="https://github.com/ibm-watson-data-lab/pixiedust">GitHub</a> by <a href="https://github.com/ibm-watson-data-lab/pixiedust/issues">creating an issue</a>. Pull requests are most welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43e190df4adb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/share-your-jupyter-notebook-charts-on-the-web-43e190df4adb">Share Your Jupyter Notebook Charts on the Web</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Your Analytics as Web Apps Using PixieDust’s 1.1 Release]]></title>
            <link>https://medium.com/codait/deploy-your-analytics-as-web-apps-using-pixiedusts-1-1-release-d08067584a14?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d08067584a14</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[ipython]]></category>
            <category><![CDATA[pixiedust]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 20:04:28 GMT</pubDate>
            <atom:updated>2017-11-08T17:48:52.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>From data science, directly to the web</h4><p><strong>Question:</strong> What? I can deploy the analytics I built in my Jupyter Notebook as a web application?</p><p><strong>Answer: </strong>Yes, this is not a typo! This latest innovation from the PixieDust team lets you deploy a PixieApp into a web application with a simple click (no added code).</p><blockquote><strong>Note:</strong> This feature is still in alpha and therefore not ready to be used in production. For more on the PixieGateway release alpha, <a href="https://ibm-watson-data-lab.github.io/pixiedust/1-1.html">see the release notes</a>.</blockquote><blockquote><strong>Note:</strong> Because of an error in the build files, we had to issue an emergency patch. The correct version for this release is now 1.1.0.1.</blockquote><h3>End-to-End analytics pipeline</h3><p>Before publishing your first PixieApp to the web, let’s quickly recap the evolution of the PixieDust helper library for Jupyter Notebooks.</p><ul><li>It started by providing two simple APIs: one to load data so you don’t have to learn the intricacies of Spark APIs, and one for auto-visualizing a data set, whether it’s a Spark/Pandas DataFrame or a GraphFrame.</li><li>Then came <a href="https://ibm-watson-data-lab.github.io/pixiedust/pixieapps.html">PixieApps</a>: they let you build embedded application UIs within notebooks that leverage your analytics and charts with minimal coding. (See this <a href="https://medium.com/ibm-watson-data-lab/visualizing-weather-data-as-a-pixieapp-c4424aae084d">nice example by</a> <a href="https://medium.com/u/6208921cf12a">Jordan George</a>.)</li></ul><p>Naturally, the next step was to free PixieApps from the limitation of running only within notebooks and to run them as regular web apps. The application lifecycle now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-p8XA_mZksYqTcgTnnDRA.png" /><figcaption>With PixieApp’s ability to publish charts from notebook code as web apps, data science notebooks now reach developers and line-of-business users.</figcaption></figure><p>Here’s the collaboration workflow:</p><ol><li>Data scientists use a Python notebook to load, enrich, analyze data, and create analytics (dashboards, reports, machine learning models, etc.).</li><li>From the same notebook, developers create a PixieApp to operationalize these analytics. Developers can also <a href="https://ibm-watson-data-lab.github.io/nodebooks">collaborate on analytics with JavaScript using PixieDust Nodebooks</a>.</li><li>Once ready, developers publish the PixieApp as a web application, where it can be easily consumed interactively by line-of-business users.</li></ol><h3>How does it work?</h3><p>The PixieGateway web application server is responsible for loading and running PixieApps. It is built on top of the <a href="https://github.com/jupyter/kernel_gateway">Jupyter Kernel Gateway</a> and therefore follows a similar architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvsNeQqegv7zQiM7FVfZcQ.png" /><figcaption>PixieGateway architecture diagram.</figcaption></figure><p>Here’s what you’ll see when you go to publish:</p><ol><li>From a Jupyter Notebook, the data scientist or developer runs the PixieApp. When ready, they can click on a new publish button (the electric plug icon 🔌) to deploy the PixieApp into the PixieGateway.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*UYeqMLMWJTJSISDQYIDYuw.png" /><figcaption>The publish button in the PixieApp UI within a notebook.</figcaption></figure><p>2. The Publish Configuration dialog contains the following panels:</p><p>a. Basic configuration info, such as server address, page title, and page icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXNmfYg5fP3dPetZ--7Q5Q.png" /><figcaption>The Basic Configuration options for publishing a PixieApp to the web.</figcaption></figure><p>b. List of package dependencies (automatically detected by static code analysis). Users will eventually be able to manually adjust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keAQS0ScfF6GBEMyPUR_qA.png" /><figcaption>List of imported packages within the Basic Configuration dialog.</figcaption></figure><p>c. Kernel Spec information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ysbNsLs7HA34ysvSYGpCw.png" /><figcaption>Kernel Spec info found within the Basic Configuration dialog.</figcaption></figure><h3>Installing the PixieGateway</h3><p>If you want to demo PixieApp publishing locally, follow these instructions. If you’d rather deploy your application to the cloud, see the next section on using Kubernetes on Bluemix.</p><p>To start, install the pixiegateway package from PyPi. On the command line, run the following: (Note: PixieGateway supports both python 2.7 and 3.x)</p><pre>pip install pixiegateway</pre><p>Then you can start the PixieGateway with a simple command:</p><pre>jupyter pixiegateway --port &lt;portnumber&gt;</pre><p>Example output:</p><pre>dtaieb$ jupyter pixiegateway --port 8899<br>[PixieGatewayApp] Kernel started: b5be0b3b-a018–4ace-95d1-d94b556a0bfe<br>kernel client initialized<br>[PixieGatewayApp] Jupyter Kernel Gateway at http://127.0.0.1:8899</pre><p>Now, go to http://localhost:&lt;portnumber&gt;/pixieapps to review and use your apps.</p><h3>[optional] Running PixieGateway in Kubernetes on IBM Bluemix</h3><p>If you’re starting with Kubernetes on the IBM Bluemix container service, then <a href="https://medium.com/ibm-watson-data-lab/zero-to-kubernetes-on-the-ibm-bluemix-container-service-fd104fd193c1">read this intro article</a> from <a href="https://medium.com/u/f1b6565b0972">Mark Watson</a> that explains the basics of using the service with the bx and kubectl command-line tools.</p><p>Here are the steps to install PixieGateway using Kubernetes on Bluemix:</p><ol><li>Download the <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">Kubernetes CLI </a>and the <a href="https://clis.ng.bluemix.net/ui/home.html">Bluemix CLI</a>.</li><li>bx login [-sso] -a https://api.ng.bluemix.net</li><li>bx target -o &lt;YOUR_ORG&gt; -s &lt;YOUR_SPACE&gt;</li><li>bx plugin install container-service -r Bluemix</li><li>bx cs init</li><li>If not already done, create a cluster: bx cs cluster-create --name my-cluster</li><li>Verify that the cluster is correctly created (this may take a few minutes): bx cs clusters</li><li>Download the cluster config: bx cs cluster-config my-cluster</li><li>Run the export command returned by the command above, e.g., export KUBECONFIG=/Users/dtaieb/.bluemix/plugins/container-service/clusters/davidcluster/kube-config-hou02-davidcluster.yml</li><li>Create the deployment: kubectl create -f https://github.com/ibm-watson-data-lab/pixiegateway/raw/master/etc/deployment.yml</li><li>Create the service: kubectl create -f https://github.com/ibm-watson-data-lab/pixiegateway/raw/master/etc/service.yml</li><li>Verify the pods: kubectl get pods</li><li>Verify the nodes: kubectl get nodes</li><li>Verify the services: kubectl get services</li><li>Finally, you can get the public ip address of the server: bx cs workers my-cluster</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b49RENKonqgt_c5QySgQJA.png" /><figcaption>Workers information</figcaption></figure><p>16. To check that the install worked, enter the following URL in your browser: http://&lt;publicIP&gt;:32222/pixieapps . You’ll be able to interact with your PixieApp-published web apps from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIMRBxPQjPsRvhTBZr_LoQ.png" /><figcaption>List of published PixieApps. Use them like regular web applications!</figcaption></figure><blockquote><strong>Note:</strong> The screenshot above shows a list of PixieApps that have already been published. Do not be alarmed if your list is empty. We’ll get to publishing apps from notebooks in the next section.</blockquote><p>17.<strong> Optional:</strong> In the future, if you need to update the PixieGateway version, you do not have to retrace the previous steps. Instead, simply delete the Kubernetes pod, which will cause Docker to restart and automatically pull down a new version of PixieDust, like so: kubectl delete pod &lt;name&gt; . Here, &lt;name&gt; is the pod’s name obtained with the command: kubectl get pods</p><blockquote><strong>Note:</strong> At the time of writing, the deployed PixieApps are not stored in a persisted volume, so deleting the pod will also delete them, and you’ll have to re-publish.</blockquote><h3>Deploying your first PixieApp</h3><p>In this section, we’ll use the sample StockViewer PixieApp.</p><ol><li>Download the <a href="https://github.com/ibm-watson-data-lab/pixiedust/blob/master/notebook/pixieapp/StockViewer.ipynb">StockViewer Notebook</a> (view the raw version and ensure it takes the .ipynb file extension when you save). Then, run it in your favorite Jupyter Notebook server, e.g., running locally or on <a href="https://datascience.ibm.com/">IBM’s DSX</a>.</li><li>Run the cell that contains the PixieApp. Notice a new publish icon on the top right of the cell output. Click on it.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xZWglB6RUfKgwFpbdjqxw.png" /><figcaption>Our new friend, the PixieApp Publish icon 🔌</figcaption></figure><p>3. In the Options pane, enter the PixieGateway server location. (This is the only required option at this time.)<em> </em>Click the Publish button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jvlXoFDkWHEIsUwGEdPwg.png" /><figcaption>Our other new friend, the PixieApp Publish Configuration dialog!</figcaption></figure><p>4. If all goes well you should see the following results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-NjRrejI04NnRHFja-OGg.png" /><figcaption>A successful PixieApp publish.</figcaption></figure><p>5. Click on the provided link and start using the PixieApp as a regular web application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MO95PXbs4PSsU1TBXeLvUQ.png" /><figcaption>The StockViewer PixieApp running as a web application. Your work just went from raw data in a Jupyter Notebook to your boss’s web browser. Congrats!</figcaption></figure><h3>What happens under the hood when I publish?</h3><p>During the publication process, PixieGateway will perform static analysis on all the cells that contain code. (Only Python is supported at this time.) It will then try to find the first cell that contains a PixieApp. It does so by looking at a Python class definition annotated with the @PixieApp annotation, for example:</p><pre>from pixiedust.display.app import *<br>@PixieApp<br>class MyApp():<br>   @route()<br>   def main_screen(self):<br>       return &quot;&lt;div&gt;Hello World&lt;/div&gt;&quot;</pre><pre>my_app = MyApp()<br>my_app.run()</pre><blockquote><strong>Note:</strong> If your notebook doesn’t contain the @PixieApp annotation, then the publishing fails.</blockquote><p><strong>A few important rules:</strong></p><ul><li>All the cells above the PixieApp cell are considered “warmup code.” This code runs only once in the host kernel, and the PixieApp can refer to the variables declared there. It is good practice to use the warmup code to store all large data sources and that would otherwise take a long time to load.</li><li>Since multiple PixieApps can run on the same IPython kernel, the variable names are automatically renamed to avoid accidental name collision with other PixieApps.</li><li>All the cells below the PixieApp cell are ignored, but you can still use them for debugging, for example.</li><li>The PixieApp cell code is considered the “run code.” When the user runs a PixieApp, the run code executes. It is important that the run code contains the PixieApp instantiation and the call to the run method (e.g., my_app = MyApp() and then my_app.run()).</li><li>It is good practice to store the PixieApp instance into its own variable (my_app = MyApp()). In this case, PixieGateway will rename the variable and assign it to the user session. Since a PixieApp can contain state, this will avoid name collision when multiple users access the sample PixieApp. If you choose to not store the PixieApp in its own variable, ensure that it doesn’t contain state (class variable).</li></ul><h3>What’s next for PixieGateway</h3><p>There is much more work left to make PixieGateway feature-complete. Broadly, here’s what’s in the works:</p><ol><li><strong>Authentication/Authorization:</strong> We’re planning to support an extensible mechanism to secure the deployed PixieApps, with a default built-in implementation.</li><li><strong>Scalability:</strong> PixieGateway needs to scale horizontally based on user load.</li><li><strong>Kernel runtime:</strong> Smart configuration of kernel based on specs provided at publish time.</li><li><strong>Spark Support:</strong> Right now, PixieGateway doesn’t support kernels connected to spark, but it will in future releases.</li><li><strong>Package dependencies:</strong> Improve automatic detection and provisioning of package dependencies, including support for versioning and editable installs (dev mode).</li></ol><p>As always, we look forward to your feedback. Continue the conversation — and pull requests — on Github at <a href="https://github.com/ibm-watson-data-lab/pixiedust">https://github.com/ibm-watson-data-lab/pixiedust</a> . Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d08067584a14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/deploy-your-analytics-as-web-apps-using-pixiedusts-1-1-release-d08067584a14">Deploy Your Analytics as Web Apps Using PixieDust’s 1.1 Release</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PixieDust gets its first community-driven feature in 1.0.4]]></title>
            <link>https://medium.com/codait/pixiedust-gets-its-first-community-driven-feature-in-1-0-4-b40c622a572e?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b40c622a572e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[jupyter]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[pixiedust]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Thu, 13 Apr 2017 19:48:39 GMT</pubDate>
            <atom:updated>2017-04-13T19:48:39.848Z</atom:updated>
            <content:encoded><![CDATA[<h4>Now with time series data, the fairy tale continues</h4><p>Last month I announced the availability of <a href="https://medium.com/ibm-watson-data-lab/pixiedust-1-0-is-here-15e0f428df88">PixieDust 1.0</a>. Since then, community adoption has been fantastic. Based on repo stars and on feedback at conferences and events, more developers and data scientists are using PixieDust as part of their work in Jupyter Notebooks.</p><p>Today, we’re <a href="https://ibm-cds-labs.github.io/pixiedust/1-0-4.html">releasing version 1.0.4</a> on PyPi, but what’s noteworthy is that this version is getting a new feature that has been prioritized by the community: time series data. (Personally, there’s no better feeling than working on a feature that users are clamoring for.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*UZJgNnDwA1NTzTgqk-cVhw.png" /><figcaption>The PixieDust fairy tale continues with time series data.</figcaption></figure><h4>Once upon a time [series]</h4><p>PixieDust now supports display of time series data for bar and line charts. Previously, when loading data into PySpark DataFrames from data sources that required schema discovery (CSVs, JSON, etc.), datetime values were often converted into strings. This caused problems when visualizing the data (sorting, formatting, etc.). Fixing it required complicated massaging of the data.</p><p>In the example below, I want to display stock values over time. Unfortunately, Spark converts the date values to Unix timestamps, and the results are not visualized correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEJl5F7XYKWJdWpbrJ9bWQ.png" /><figcaption>PixieDust: before using the new time series option in version 1.0.4. Unix timestamps muddy the sort order.</figcaption></figure><p>Users can now click the “Time Series” checkbox to have PixieDust automatically convert this data into a correctly formatted date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmANiQoDDjtXQh1p3tZG6A.png" /><figcaption>PixieDust: after applying the new time series option. Unix timestamps are now converted into datetime64 values and sorted properly.</figcaption></figure><h4>Gaze upon the crystal ball of PixieDust: Pixie Apps</h4><p>I’ll let you in on a secret: there is a bigger feature that has been dark-launched with PixieDust 1.0.4. Even though it’s not ready yet, I thought I would float the idea here for feedback as we refine the design.</p><p>This new feature is called “Pixie App.” Some of its features, like routes, are inspired by the popular <a href="https://angularjs.org/">AngularJS framework</a> for web apps, but applied to the context of data science notebooks. The idea is to let developers easily create bigger building blocks that encapsulate their data (Model), UI (View) and logic (Controller). MVC, anyone?</p><p>Pixie App lets you refactor your projects for speed and repeatability. For example, you could use it to build an interactive dashboard with widgets communicating via events, or automate part of a machine learning pipeline that requires multiple manual steps and replace it with a nice UI.</p><p>From a developer’s perspective, Pixie Apps have been designed to minimize boilerplate code. All you need to get started is create a Python class and provide HTML fragments for each widget. The logic, workflow, entity, and event handling is expressed via HTML, microformats, and embedded Python.</p><p>Here’s some sample code, for an idea:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/068e1389808d51a26b63c15887bfb499/href">https://medium.com/media/068e1389808d51a26b63c15887bfb499/href</a></iframe><p>To run the sample app above, you’ll need some data. (Note: for Pixie Apps, you don’t always necessarily <em>need</em> data.) The code below creates a simple PySpark DataFrame, which is passed to the run function. It also uses the runInDialog=&#39;true&#39; option to automatically display the app in a dialog, as opposed to the cell’s output:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8f7af9bf8ba2521ce15ed72588b70d4/href">https://medium.com/media/b8f7af9bf8ba2521ce15ed72588b70d4/href</a></iframe><p>The results are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_RsVKFiZB8qfwA_gY2QOw.png" /><figcaption>Click the “Run custom Python script” button.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5iR7aEU8YCj2dRA4GpOzOg.png" /><figcaption>Click the “Show Bar Chart” button.</figcaption></figure><h4>The next chapter</h4><p>More documentation on Pixie Apps will come soon, but for now you can upgrade your PixieDust version to 1.0.4 and try the sample Pixie App above.</p><p>Let’s get the <a href="https://github.com/ibm-cds-labs/pixiedust/issues/287">Pixie App discussion started on Github</a>. I can’t wait to hear your feedback and ideas.</p><p>Click the ♡ here to sprinkle a bit of Medium love in the name of PixieDust. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b40c622a572e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/pixiedust-gets-its-first-community-driven-feature-in-1-0-4-b40c622a572e">PixieDust gets its first community-driven feature in 1.0.4</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PixieDust 1.0 is here!]]></title>
            <link>https://medium.com/codait/pixiedust-1-0-is-here-15e0f428df88?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/15e0f428df88</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[pixiedust]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Wed, 08 Mar 2017 17:36:51 GMT</pubDate>
            <atom:updated>2017-03-23T22:31:36.123Z</atom:updated>
            <content:encoded><![CDATA[<h4>Notebook data visualizations for everyone</h4><p>Back in October of last year, I <a href="https://developer.ibm.com/clouddataservices/2016/10/11/pixiedust-magic-for-python-notebook/">introduced</a> the <a href="https://github.com/ibm-cds-labs/pixiedust">PixieDust open source project</a>. PixieDust is a helper library for Python or Scala notebooks, which lets you generate sophisticated charts, maps, and other visualizations in a few clicks — no coding necessary. It smooths out some other pain points for notebook users too, which you’ll read about in a minute. PixieDust got <a href="https://github.com/ibm-cds-labs/pixiedust/stargazers">lots of interest</a> from the community. Thank you all for <a href="https://github.com/ibm-cds-labs/pixiedust/issues">your feedback</a>, which is helping us refine the tool.</p><h3>The magic is bottled</h3><p>Finally, the wait is over. After much hard work from the team, I am happy to announce the availability of <a href="https://pypi.python.org/pypi/pixiedust">PixieDust 1.0 on PyPi</a>. Can’t wait to see it? Here’s a quick video showing PixieDust’s display() API and chart rendering in action:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFoOHFlkCaXI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFoOHFlkCaXI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFoOHFlkCaXI%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/750d397850469e70dcddce0c24ba6744/href">https://medium.com/media/750d397850469e70dcddce0c24ba6744/href</a></iframe><h3>New features</h3><h4><strong>Multi-renderer support</strong></h4><p>PixieDust offers several different rendering engines you can use out-of-the-box to display your data. Depending upon what chart you’re viewing, render with <strong>matplotlib</strong>, <strong>Bokeh</strong>, or <strong>Seaborn </strong>— all without coding a single extra line. You can also generate sophisticated, gorgeous maps from your data using <strong>Mapbox</strong> or <strong>Google Maps</strong>.</p><h4><strong>Spark Progress Monitor</strong></h4><p>Track the status of your Spark job. No more waiting in the dark. Notebook users can now see how a cell’s code is running behind the scenes.</p><h4><strong>Installer for local use</strong></h4><p>We’ve made it easier to get started with PixieDust locally. <a href="https://ibm-cds-labs.github.io/pixiedust/install.html">Try our new packaged installer</a>. It will walk you through setup, step by step.</p><h4>Scala in a Python notebook</h4><p>Enter Scala commands in a Python notebook. Variables are automatically transferred from Python to Scala and vice-versa.</p><h3>Improvements</h3><h4><strong>Extensibility Guidance</strong></h4><p>Want to create your own visualizations or add a renderer? We help you understand how to build add-ons with a generate wizard, which walks you through a sample setup using Terminal or other command line tools.</p><h4><strong>Display improvements</strong></h4><p>We continue to refine and improve PixieDust’s display() API with smarter introspection of your DataFrames and expanded options for data visualizations.</p><h4>That’s just the latest</h4><p>As before, PixieDust lets you install Spark packages inside a Python notebook, export data, embed a polished app UI in your notebook, and more. For details on these and other features, <a href="https://github.com/ibm-cds-labs/pixiedust">visit PixieDust’s readme</a>.</p><h3>Coming soon</h3><h4><strong>Full Scala notebook support</strong></h4><p>Love Scala, but crave the robust visualizations that only Python can deliver? Fear not, Matplotlib lovers — soon, there’ll be no need to choose!</p><p>PixieDust will soon work in Scala notebooks too, letting you configure robust and varied data display options in just a few clicks (no coding necessary). To see a preview, watch the video above or <a href="https://youtu.be/qetedQg8m3k?t=3m37s">jump straight to it</a> on YouTube.</p><h3>Try it yourself</h3><p>To help you get started, we offer some sample notebooks. <a href="https://ibm-cds-labs.github.io/pixiedust/">Give PixieDust a try</a> and share your issues, comments, and ideas on GitHub. PRs welcome!</p><p>Also, spread the magic. Click the ♡ here to sprinkle a bit of love in the name of PixieDust.</p><p>Oh, hey. Did we forget to mention? We have a new logo too:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6eAS_bXeK4S0ZdgevpM3g.png" /><figcaption>Sprinkling data science magic since 2016.</figcaption></figure><p><strong><em>Acknowledgements:</em></strong><em> Since there would be no magic without passion, I want to thank </em><a href="https://medium.com/u/733af9cd0209"><em>va barbosa</em></a><em>, </em><a href="https://medium.com/u/f703102edd01"><em>Mike Broberg</em></a><em>, </em><a href="https://medium.com/u/169764cd652d"><em>Jess Mantaro</em></a><em>, </em><a href="https://medium.com/u/b84e41941736"><em>Brad Noble</em></a><em>, </em><a href="https://medium.com/u/b650e7381f14"><em>RAJ SINGH</em></a><em>, </em><a href="https://medium.com/u/df9e907db0b1"><em>Patrick Titzler</em></a><em>, </em><a href="https://medium.com/u/705a4805cf41"><em>Chetna Warade</em></a><em>, </em><a href="https://medium.com/u/f1b6565b0972"><em>Mark Watson</em></a> <em>, and the rest of the of the IBM Watson Data Platform developer advocacy team for their dedication and long hours trying to make data simple and accessible.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15e0f428df88" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/pixiedust-1-0-is-here-15e0f428df88">PixieDust 1.0 is here!</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-Time Sentiment Analysis of Twitter Hashtags with Spark]]></title>
            <link>https://medium.com/codait/real-time-sentiment-analysis-of-twitter-hashtags-with-spark-7ee6ca5c1585?source=rss-23afa685a28e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ee6ca5c1585</guid>
            <category><![CDATA[pixiedust]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[David Taieb]]></dc:creator>
            <pubDate>Tue, 20 Dec 2016 12:01:01 GMT</pubDate>
            <atom:updated>2017-09-18T13:56:41.531Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sentiment Analysis of Twitter Hashtags With Spark</h3><h4>Revisited with PixieDust &amp; Jupyter Notebooks</h4><h3>Why do it again?</h3><p>This is <em>yet another blog post</em> where I discuss the application I built for running sentiment analysis of Twitter content using <a href="http://spark.apache.org/">Apache Spark™</a> and <a href="https://console.ng.bluemix.net/catalog/services/tone-analyzer">Watson Tone Analyzer</a>. Before you quit reading, let me assure you that there is a good reason to revisit this code, and that you will hopefully learn something new.</p><p>Let’s first recap the first two installments:</p><ol><li>In <a href="https://developer.ibm.com/clouddataservices/2015/10/06/sentiment-analysis-of-twitter-hashtags/">Part 1</a>, I built a Spark Streaming application in Scala that I invoked in a Scala Notebook to fetch live Twitter content. I then used a Python Notebook to build analytics on the data.</li><li>In <a href="https://developer.ibm.com/clouddataservices/2016/01/15/real-time-sentiment-analysis-of-twitter-hashtags-with-spark/">Part 2</a>, I tried to improve the application to update in real time. To do that, I ported the analytics in the Scala Spark Streaming piece, sending the results to a dashboard via <a href="https://console.ng.bluemix.net/catalog/services/message-hub">MessageHub</a> events (based on <a href="https://kafka.apache.org/">Apache Kafka™</a>). The dashboard was a Node.js application that displays the <a href="https://d3js.org/">D3</a> charts (deployed on <a href="https://console.ng.bluemix.net/">IBM Bluemix</a>), which were updated continuously from the data received via MessageHub.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*1guVzUU1J3LED_aL1DC8JA.jpeg" /><figcaption>But wait! There’s good reason to revisit this code.</figcaption></figure><p>Great! But a few things about the application still bothered me:</p><ol><li>The application was accessible to developers, but other users found it hard to deploy. To be fair, configuring the Node.js dashboard, the MessageHub service, the Weather service, the Watson Tone Analyzer service, and Spark Streaming was error prone. You had to ensure that the credentials, Kafka topics, etc. all matched in every place. Pretty hateful no?</li><li>Data scientists lost the flexibility to further analyze the results. Everything was now in black boxes, namely the Spark Streaming Scala app and the Node.js dashboard code.</li></ol><h3>Can we do better?</h3><p>For the third version of this app, I had two basic goals:</p><ol><li>Use only one flavor of data science notebook. Asking people to use a Scala Notebook first <em>and then</em> a Python Notebook created a lot of friction in previous versions of the app.</li><li>No deployment and configuration changes should be required for the front-end.</li></ol><p>The user story should be simple: a developer, data scientist, or line-of-business user should be able to run the application end-to-end from within a single Python Notebook. <strong>Difficult? Yes. Impossible? No.</strong></p><p>Now that I’ve piqued your interest, read on!</p><h3>PixieDust</h3><p>To achieve my goals I needed three capabilities:</p><ol><li>The ability to run Scala code from within a Python Notebook (the Spark Streaming application from Part 1 requires Scala).</li><li>The ability to install third-party Java packages into a Python Notebook.</li><li>The ability to run a fully functional UI from within a Python Notebook.</li></ol><p>Thankfully, PixieDust provides these three capabilities and more. You can learn more about PixieDust on GitHub: <a href="https://github.com/ibm-cds-labs/pixiedust">https://github.com/ibm-cds-labs/pixiedust</a>. There’s also an intro post: <a href="https://developer.ibm.com/clouddataservices/2016/10/11/pixiedust-magic-for-python-notebook/">PixieDust: Magic for Your Python Notebook</a>.</p><blockquote>You can easily install the PixieDust Python module in your notebook by using the following command: !pip install --user —-upgrade pixiedust</blockquote><h3>Running Scala from a Python Notebook</h3><p>In this section, we’ll recreate the app from Part 1, using only one Python Notebook.</p><p><strong>Step 1:</strong> Install the Spark Streaming Scala application into your Python Notebook using the installPackage API.</p><pre>import pixiedust<br>jarPath = &quot;https://github.com/ibm-cds-labs/spark.samples/raw/master/dist/streaming-twitter-assembly-1.6.jar&quot;<br>pixiedust.installPackage(jarPath)</pre><p>You should see the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GeUEC040ADHnP1LU." /><figcaption>“PixieDust database opened successfully” &amp; more victorious output!</figcaption></figure><blockquote>Look out for the red message asking you to restart the kernel. There’s more information on the <a href="https://github.com/ibm-cds-labs/pixiedust/wiki/Package-Manager">PixieDust package manager</a>.</blockquote><p><strong>Step 2:</strong> Store your credentials. We’ll reuse them a lot, so it’s best to store them in Python variables. We’ll then use the PixieDust Scala bridge to make Python variables available in Scala code.</p><blockquote>Replace the XXXX below with your own credentials as explained in <a href="https://developer.ibm.com/clouddataservices/sentiment-analysis-of-twitter-hashtags/">Part 1</a>.</blockquote><pre>twitterConsumerKey = &quot;XXXX&quot;<br>twitterConsumerSecret = &quot;XXXX&quot;<br>twitterAccessToken = &quot;XXXX&quot;<br>twitterAccessTokenSecret = &quot;XXXX&quot;<br>toneAnalyzerPassword = &quot;XXXX&quot;<br>toneAnalyzerUserName = &quot;XXXX&quot;</pre><p><strong>Step 3:</strong> Run the Spark Streaming app. We can now use the %%scala magic to write the code that runs the Spark Streaming application. Notice how we are using the credential variables declared above without the need to declare them explicitly—all thanks to PixieDust variable auto-binding.</p><pre>%%scala<br>val demo = com.ibm.cds.spark.samples.StreamingTwitter<br>demo.setConfig(&quot;twitter4j.oauth.consumerKey&quot;,twitterConsumerKey)<br>demo.setConfig(&quot;twitter4j.oauth.consumerSecret&quot;,twitterConsumerSecret)<br>demo.setConfig(&quot;twitter4j.oauth.accessToken&quot;,twitterAccessToken)<br>demo.setConfig(&quot;twitter4j.oauth.accessTokenSecret&quot;,twitterAccessTokenSecret)<br>demo.setConfig(&quot;watson.tone.url&quot;,&quot;https://gateway.watsonplatform.net/tone-analyzer/api&quot;)<br>demo.setConfig(&quot;watson.tone.password&quot;,toneAnalyzerPassword)<br>demo.setConfig(&quot;watson.tone.username&quot;,toneAnalyzerUserName)</pre><pre>//Run the Spark streaming for a limited time<br>import org.apache.spark.streaming._<br>demo.startTwitterStreaming(sc, Seconds(30))</pre><p>You should see the following results:</p><pre>Starting twitter stream<br>Twitter stream started<br>Tweets are collected real-time and analyzed<br>To stop the streaming and start interacting with the data use: StreamingTwitter.stopTwitterStreaming<br>Receiver Started: TwitterReceiver-0<br>Batch started with 105 records<br>Batch completed with 105 records<br>Batch started with 246 records<br>Stopping Twitter stream. Please wait this may take a while<br>Receiver Stopped: TwitterReceiver-0<br>Reason:  : Stopped by driver<br>Batch completed with 246 records<br>Twitter stream stopped<br>You can now create a sqlContext and DataFrame with 24 Tweets created. Sample usage: <br>val (sqlContext, df) = com.ibm.cds.spark.samples.StreamingTwitter.createTwitterDataFrames(sc)<br>df.printSchema<br>sqlContext.sql(&quot;select author, text from tweets&quot;).show</pre><blockquote>Here’s more information on the <a href="https://github.com/ibm-cds-labs/pixiedust/wiki/Using-Scala-language-within-a-Python-Notebook">PixieDust Scala bridge</a>.</blockquote><p><strong>Step 4:</strong> Collect tweets enriched with Tone Analyzer scores and move them into a Spark DataFrame. Wait until Spark Streaming has finished and run the following cell:</p><pre>%%scala<br>val demo = com.ibm.cds.spark.samples.StreamingTwitter<br>val (__sqlContext, __df) = demo.createTwitterDataFrames(sc)</pre><p>In this cell, we again use Scala to call the createTwitterDataFrames API. Notice how we add special characters __ to each of the variables. The underscores tell the Scala bridge that these variables need to be bound as Python variables. We’ll use them again to do some data science.</p><p>You should see the following results:</p><pre>A new table named tweets with 24 records has been correctly created and can be accessed through the SQLContext variable<br>Here&#39;s the schema for tweets<br>root<br> |-- author: string (nullable = true)<br> |-- userid: string (nullable = true)<br> |-- date: string (nullable = true)<br> |-- lang: string (nullable = true)<br> |-- text: string (nullable = true)<br> |-- lat: double (nullable = true)<br> |-- long: double (nullable = true)<br> |-- Anger: double (nullable = true)<br> |-- Disgust: double (nullable = true)<br> |-- Fear: double (nullable = true)<br> |-- Joy: double (nullable = true)<br> |-- Sadness: double (nullable = true)<br> |-- Analytical: double (nullable = true)<br> |-- Confident: double (nullable = true)<br> |-- Tentative: double (nullable = true)<br> |-- Openness: double (nullable = true)<br> |-- Conscientiousness: double (nullable = true)<br> |-- Extraversion: double (nullable = true)<br> |-- Agreeableness: double (nullable = true)<br> |-- EmotionalRange: double (nullable = true)</pre><p><strong>Step 5:</strong> Do some data science. (See? I told you.) We are now able to run the same analytics from the Python Notebook in <a href="https://developer.ibm.com/clouddataservices/sentiment-analysis-of-twitter-hashtags/">Part 1</a>:</p><pre>tweets=__df<br>tweets.count()<br>display(tweets)</pre><blockquote>Here we use the PixieDust display API to explore the data. The <a href="https://github.com/ibm-cds-labs/pixiedust/wiki/PixieDust-display-API">PixieDust GitHub wiki</a> again has everything you need to know about display.</blockquote><p>You should see the following results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gn15Y5ywz35h6uin." /></figure><blockquote>You can optionally run the other analytics from <a href="https://developer.ibm.com/clouddataservices/sentiment-analysis-of-twitter-hashtags/">Part 1</a>. They are pretty much the same.</blockquote><h3>What about the line-of-business user?</h3><p>The previous section represents a great improvement over Part 1, as we now can run the application end-to-end from within a single Python Notebook. However, we still have a lot of code and syntax to deal with, and we don’t yet have real-time analytics.</p><p>In this section, we’ll show how to create a PixieDust embedded UI with real-time analytics.</p><p><strong>Step 1:</strong> Create a PixieDust plugin. Create a new Github repo and add a <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/setup.py">setup.py</a> file as follows:</p><pre>from setuptools import setup<br>setup(name=&#39;pixiedust_twitterdemo&#39;,<br>      version=&#39;0.3&#39;,<br>      description=&#39;Pixiedust demo of the Twitter Sentiment Analysis tutorials&#39;,<br>      url=&#39;https://github.com/ibm-cds-labs/pixiedust_incubator/tree/master/twitterdemo&#39;,<br>      install_requires=[&#39;pixiedust&#39;],<br>      author=&#39;David Taieb&#39;,<br>      author_email=&#39;david_taieb@us.ibm.com&#39;,<br>      license=&#39;Apache 2.0&#39;,<br>      packages=[&#39;pixiedust_twitterdemo&#39;],<br>      include_package_data=True,<br>      zip_safe=False)</pre><blockquote>See it in context on GitHub in the <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/tree/master/twitterdemo">pixiedust_incubator/twitterdemo</a> repo.</blockquote><p><strong>Step 2:</strong> Create your controller class. The controller class tells PixieDust when to trigger the display class. It must inherit from DisplayHandlerMeta found in <a href="https://github.com/ibm-cds-labs/pixiedust/blob/master/pixiedust/display/display.py">display.py</a>. Then, in <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/pixiedust_twitterdemo/__init__.py">init.py</a>:</p><pre>from pixiedust.display import *<br>...</pre><pre>class PixieDustTwitterDemoPluginMeta(DisplayHandlerMeta):</pre><pre>  @addId<br>  def getMenuInfo(self,entity):<br>    if entity==self.__class__:<br>      return [{&quot;id&quot;: &quot;twitterdemo&quot;}]<br>    else:<br>      return []</pre><pre>  def newDisplayHandler(self,options,entity):<br>    return PixieDustTwitterDemo(options,entity)</pre><p><strong>Step 3:</strong> Create the display class. This class contains the logic for processing and displaying the results. It must inherit from the Display class found <a href="https://github.com/ibm-cds-labs/pixiedust/blob/master/pixiedust/display/display.py">display.py</a>. Then, in <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/pixiedust_twitterdemo/twitterDemo.py">twitterDemo.py</a>:</p><pre>class PixieDustTwitterDemo(Display):<br>    ...<br>  def doRender(self, handlerId):<br>    self.addProfilingTime = False<br>    stream = self.options.get(&quot;stream&quot;)</pre><pre>    if stream is None:<br>      self._addScriptElement(&quot;<a href="https://d3js.org/d3.v3.js">https://d3js.org/d3.v3.js</a>&quot;, checkJSVar=&quot;d3&quot;, <br>        callback=[self.renderTemplate(&quot;demoPieChart.js&quot;), self.renderTemplate(&quot;demoGroupedChart.js&quot;)]<br>      )<br>      self._addHTMLTemplate(&quot;demoScript.html&quot;)<br>      self._addHTMLTemplate(&quot;demo.html&quot;)</pre><pre>    elif stream is True or str(stream).lower() == &#39;true&#39;:<br>      self.startStream()</pre><pre>    elif stream is False or str(stream).lower() == &#39;false&#39;:<br>      self.stopStream()<br>  def genStartStreamingExecuteCode(self):<br>    return self.renderTemplate(&quot;startStreaming.execute&quot;, <br>      channel = StreamingChannel.__module__ + &quot;.&quot; + StreamingChannel.__name__,<br>      receiver = &quot;com.ibm.cds.spark.samples.PixiedustStreamingTwitter$&quot;,<br>      scalaCode = &quot;val demo = com.ibm.cds.spark.samples.PixiedustStreamingTwitter;demo.startStreaming();print(\\\&quot;done\\\&quot;)&quot;)</pre><blockquote>There’s is a lot happening in this example. If you’re interested in diving in deeper, we’ll publish a <a href="https://github.com/ibm-cds-labs/pixiedust/wiki/How-to-write-a-new-PixieDust-visualization">hello-world example</a> in January to help you follow along.</blockquote><p>Let’s look at a few key points: the doRender method is called by the framework to process and render the visualization. The class is passed the following objects:</p><ol><li>self.entity: the entity containing the data being displayed (not used above, but available for use)</li><li>self.options: dictionary of state variables</li><li>self._addHTMLTemplate: helper method that takes a path to a <a href="http://jinja.pocoo.org/docs/dev/templates/">jinja2</a> template; the template is guaranteed to be passed a few variables like entity, prefix, etc.</li><li>self._addScriptElement: helper method that lets you insert a JavaScript file into the browser client</li></ol><blockquote>I’m glossing over many details in this article. I encourage you to study the code to understand how I’m creating a dialog box for the UI from within the <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/pixiedust_twitterdemo/templates/demo.html">demo.html</a> template—specifically, how I use the <a href="https://github.com/ibm-cds-labs/pixiedust/blob/master/pixiedust/display/templates/basedialog.html">basedialog.html</a> macro.</blockquote><p><strong>Step 4:</strong> Create your simple API. We are now ready to create a simple wrapper API that the user can just call from a notebook. In <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/pixiedust_twitterdemo/__init__.py">init.py</a>:</p><pre>def twitterDemo():<br>  display(PixieDustTwitterDemoPluginMeta)</pre><p>The twitterDemo method is wrapping a call to display, passing data that is specific to this plugin.</p><p><strong>Step 5</strong>: Use our new application in a notebook. First, set the credentials again, this time for the PixiedustStreamingTwitter class:</p><pre>%%scala<br>val demo = com.ibm.cds.spark.samples.PixiedustStreamingTwitter<br>demo.setConfig(&quot;twitter4j.oauth.consumerKey&quot;,twitterConsumerKey)<br>demo.setConfig(&quot;twitter4j.oauth.consumerSecret&quot;,twitterConsumerSecret)<br>demo.setConfig(&quot;twitter4j.oauth.accessToken&quot;,twitterAccessToken)<br>demo.setConfig(&quot;twitter4j.oauth.accessTokenSecret&quot;,twitterAccessTokenSecret)<br>demo.setConfig(&quot;watson.tone.url&quot;,&quot;https://gateway.watsonplatform.net/tone-analyzer/api&quot;)<br>demo.setConfig(&quot;watson.tone.password&quot;,toneAnalyzerPassword)<br>demo.setConfig(&quot;watson.tone.username&quot;,toneAnalyzerUserName)<br>demo.setConfig(&quot;checkpointDir&quot;, System.getProperty(&quot;user.home&quot;) + &quot;/pixiedust/ssc&quot;)</pre><p>And then in the next cell, call the twitterDemo API:</p><pre>from pixiedust_twitterdemo import *<br>twitterDemo()</pre><p>You should see a dialog that lets you specify word filters in the top left corner. It also shows you the tweets in tiles as they arrive. Clicking on an individual tweet tile will reveal the Watson Tone Analyzer scores for that tweet. Click the <strong>Start Streaming</strong> button, and you should start seeing tweets that match your filters. The UI also displays real-time sentiment analysis charts. To go back to the notebook, simply click the <strong>Back to Notebook</strong> button. The dialog is dismissed, and a new Spark DataFrame called __tweets containing the collected tweets is created. Feel free to run the analytics above on this DataFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EYpoOlCdkTLcZ0Zv." /></figure><p>Finally, you can create and customize a real-time analytics environment from the context of a Python Notebook, with the UI elements your line-of-business colleagues typically expect.</p><h3>Running the application from GitHub</h3><p>While the application can be run from any Jupyter Notebook environment, the instructions outlined below will use the <a href="http://datascience.ibm.com/">IBM Data Science Experience</a> (DSX). The first step is to get the <a href="https://github.com/ibm-cds-labs/pixiedust_incubator/blob/master/twitterdemo/notebook/Twitter%20Sentiment%20with%20Watson%20and%20PixieDust.ipynb">Twitter sentiment with Pixiedust notebook </a>into DSX:</p><ol><li>Sign into <a href="http://datascience.ibm.com/">DSX</a></li><li>Create a new project (or select an existing project)</li><li>Add a new notebook within the project:</li></ol><ul><li>Click <strong>add notebook</strong></li><li>Choose <strong>From URL</strong></li><li>Enter notebook name</li><li>Enter the notebook URL: <a href="https://raw.githubusercontent.com/ibm-cds-labs/pixiedust_incubator/master/twitterdemo/notebook/Twitter%20Sentiment%20with%20Watson%20and%20PixieDust.ipynb">https://raw.githubusercontent.com/ibm-cds-labs/pixiedust_incubator/master/twitterdemo/notebook/Twitter%20Sentiment%20with%20Watson%20and%20PixieDust.ipynb</a></li><li>Select the <strong>Spark Service</strong></li><li>Click <strong>Create Notebook</strong></li></ul><p>If prompted, select a kernel for the notebook. The notebook should successfully import.</p><h3>Conclusion</h3><p>There you have it: the third installment of the Twitter sentiment application is an elegant solution running entirely in a Python Notebook—and it’s easy to install and configure, thanks to the magic of PixieDust.</p><p>I currently have no plan for a fourth installment, but if you have an idea you’d like to share, please contact me via <a href="/service/mailto:david_taieb@us.ibm.com">email</a> or <a href="https://twitter.com/DTAIEB55">Twitter</a>. I can’t wait to hear the many good ideas to improve this application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ee6ca5c1585" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codait/real-time-sentiment-analysis-of-twitter-hashtags-with-spark-7ee6ca5c1585">Real-Time Sentiment Analysis of Twitter Hashtags with Spark</a> was originally published in <a href="https://medium.com/codait">Center for Open Source Data and AI Technologies</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>