<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>sparklyr on R Views</title>
    <link>https://rviews.rstudio.com/tags/sparklyr/</link>
    <description>Recent content in sparklyr on R Views</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 16 Aug 2017 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rviews.rstudio.com/tags/sparklyr/" rel="self" type="application/rss+xml" />
    
    
    
    
    <item>
      <title>Visualizations with R and Databases</title>
      <link>https://rviews.rstudio.com/2017/08/16/visualizations-with-r-and-databases/</link>
      <pubDate>Wed, 16 Aug 2017 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2017/08/16/visualizations-with-r-and-databases/</guid>
      <description>
        


&lt;div id=&#34;the-challenge&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;The Challenge&lt;/h2&gt;
&lt;p&gt;Visualizations are one of R’s strengths. There are many functions and packages that create complex plots, often with one simple command. These plotting functions do two things: first, they take the raw data and run the calculations needed for a given visualization, and second, they draw the plot. If the source of the data resides within a database, the usual approach is to import all of the data and then create the plot. This is a problem, especially if the data is large.&lt;/p&gt;
&lt;p&gt;A strategy to address this problem is found in the new &lt;a href=&#34;http://db.rstudio.com/&#34;&gt;Database with RStudio&lt;/a&gt; website. The &lt;a href=&#34;http://db.rstudio.com/visualization/&#34;&gt;Creating Visualizations&lt;/a&gt; page outlines a solution that introduces the &lt;em&gt;“Transform in Database, plot in R”&lt;/em&gt; concept, and demonstrates its practical implementation. The article focused on knowledge sharing, rather than on providing a tool.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;introducing-dbplot&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Introducing &lt;code&gt;dbplot&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The new &lt;code&gt;dbplot&lt;/code&gt; package is meant to collect multiple functions for in-database visualization code. It implements the principles laid out in the &lt;a href=&#34;http://db.rstudio.com/visualization/&#34;&gt;Creating Visualizations&lt;/a&gt; page, and it provides three types of functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Helper functions that return a &lt;code&gt;ggplot2&lt;/code&gt; visualization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helper functions that return the results of the plot’s calculations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;db_bin()&lt;/code&gt; function introduced in the &lt;strong&gt;Creating Visualizations&lt;/strong&gt; page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The package provides calculations or “base” &lt;code&gt;ggplot2&lt;/code&gt; visualizations for the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bar plot&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Line plot&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Histogram&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Raster&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;installation&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;Install &lt;code&gt;dbplot&lt;/code&gt; from GitHub using the &lt;code&gt;devtools&lt;/code&gt; package&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;devtools::install_github(&amp;quot;edgararuiz/dbplot&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;example&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;This example will use a Microsoft SQL Server database connection to provide a quick glance of how the package works. For more examples, please visit the &lt;a href=&#34;https://github.com/edgararuiz/dbplot&#34;&gt;package’s GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;div id=&#34;dbplot-functions&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;&lt;strong&gt;dbplot&lt;/strong&gt; functions&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;dbplot_histogram()&lt;/code&gt; function creates a 30-bin histogram by default. Because it uses &lt;code&gt;dplyr&lt;/code&gt; commands to perform the bin calculations, the function will work with any database that has &lt;code&gt;dplyr&lt;/code&gt; support, including &lt;code&gt;sparklyr&lt;/code&gt;. The only caveat is that the database must support basic functions like &lt;code&gt;max()&lt;/code&gt; and &lt;code&gt;min()&lt;/code&gt;, which some database types do not support.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(dbplyr)

tbl(con, &amp;quot;airports&amp;quot;) %&amp;gt;% 
  dbplot_histogram(alt)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2017-08-14-database-visualize_files/figure-html/unnamed-chunk-3-1.png&#34;, width = 500, height = 400&gt;&lt;/p&gt;
&lt;p&gt;This example shows how the resulting plot object can be further refined after the &lt;code&gt;dbplot_histogram()&lt;/code&gt; function returns a plot:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tbl(con, &amp;quot;airports&amp;quot;) %&amp;gt;% 
  dbplot_histogram(alt, binwidth = 700) + 
  labs(title = &amp;quot;Airports Altitude&amp;quot;) +
  theme_minimal()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2017-08-14-database-visualize_files/figure-html/unnamed-chunk-4-1.png&#34;, width = 500, height = 400&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;db_compute-functions&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;&lt;strong&gt;db_compute&lt;/strong&gt; functions&lt;/h3&gt;
&lt;p&gt;If more control over the plot is needed, then the &lt;code&gt;db_compute_bins()&lt;/code&gt; function returns a data frame with the lowest value of each bin and the record count per bin:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tbl(con, &amp;quot;airports&amp;quot;) %&amp;gt;% 
  db_compute_bins(alt)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br/&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;## # A tibble: 28 x 2
##       alt count
##     &amp;lt;dbl&amp;gt; &amp;lt;int&amp;gt;
##  1  -54.0   559
##  2  250.4   176
##  3  554.8   203
##  4  859.2   131
##  5 1163.6    82
##  6 1468.0    40
##  7 1772.4    20
##  8 2076.8    18
##  9 2381.2    16
## 10 2685.6    12
## # ... with 18 more rows&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The results of the compute command can then be piped into a plot:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tbl(con, &amp;quot;airports&amp;quot;) %&amp;gt;% 
  db_compute_bins(alt) %&amp;gt;%
  ggplot() +
  geom_col(aes(alt, count, fill = count))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2017-08-14-database-visualize_files/figure-html/unnamed-chunk-6-1.png&#34;, width = 500, height = 400&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;db_bin&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;&lt;strong&gt;db_bin()&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;dbplot&lt;/code&gt; package includes the &lt;code&gt;db_bin()&lt;/code&gt; function, first introduced in the &lt;strong&gt;Creating Visualizations&lt;/strong&gt; page. For more information, please read the &lt;a href=&#34;http://db.rstudio.com/visualization/#histogram&#34;&gt;Histogram&lt;/a&gt; section.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;db_bin(any_field)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br/&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;## (((max(any_field) - min(any_field))/(30)) * ifelse((as.integer(floor(((any_field) - 
##     min(any_field))/((max(any_field) - min(any_field))/(30))))) == 
##     (30), (as.integer(floor(((any_field) - min(any_field))/((max(any_field) - 
##     min(any_field))/(30))))) - 1, (as.integer(floor(((any_field) - 
##     min(any_field))/((max(any_field) - min(any_field))/(30))))))) + 
##     min(any_field)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;next-steps&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Next steps&lt;/h2&gt;
&lt;p&gt;More plots will be possible as &lt;code&gt;dplyr&lt;/code&gt;-to-SQL translations are fine-tuned and enhanced. The &lt;code&gt;dbplot&lt;/code&gt; package will be the place where new calculations and plots will be implemented.&lt;/p&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2017/08/16/visualizations-with-r-and-databases/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>Introducing sparklyr to the Madrid R User Group</title>
      <link>https://rviews.rstudio.com/2017/01/20/introducing-sparklyr-to-the-madrid-r-user-group/</link>
      <pubDate>Fri, 20 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2017/01/20/introducing-sparklyr-to-the-madrid-r-user-group/</guid>
      <description>
        &lt;p&gt;In the last meeting of 2016, the 40th in Madrid’s R Users Group five-year history, we had the opportunity to listen (via Skype) to a very interesting talk by Javier Luraschi, the main author of the package sparklyr.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;images/madrid_advert.png&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;

&lt;p&gt;In our previous meeting, a colleague of the Community (José Luis Cañadas) made a first introduction to sparklyr. José Luis presented the processing capacities of sparklyr on a Spark instance, as well as an interface with the h2o package. His presentation was very well-received, and generated considerable excitement for Javier’s talk.&lt;/p&gt;

&lt;p&gt;In his presentation, Javier presented background information and details on the sparklyr package, including how it was conceived and launched, its development scheme, and what is involved in setting up sparklyr on a production cluster. Javier showed how to deploy sparlkyr on Amazon EMR, and how to use RStudio Server to use the machine learning algorithms of the Spark MLlib libraries with dplyr syntax.&lt;/p&gt;

&lt;p&gt;Javier covered all these items very thoroughly in his presentation, and also presented the new changes coming with the then forthcoming release (version 0.5 was officially released some days later).&lt;/p&gt;

&lt;p&gt;During the Q&amp;amp;A section, Javier provided additional details:
* The intention to continue to support Spark.
* Clarified information about how Cloudera supports sparklyr (Cloudera recommends the use of sparkly with the version of Spark 1.6.2)&lt;/p&gt;

&lt;p&gt;On behalf of Madrid’s R User Group, we want to thank Javier for his willingness to participate in our meeting, and for his excellent work leading the development with sparklyr.&lt;/p&gt;

&lt;p&gt;Note: All sessions of the Madrid’s R User Group are recorded on video. The videos, presentations, and the code of these two meetings can be found (in Spanish) at the URLs given above.&lt;/p&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2017/01/20/introducing-sparklyr-to-the-madrid-r-user-group/&#39;;&lt;/script&gt;
      </description>
    </item>
    
  </channel>
</rss>
