You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<li><ahref="#providing-a-data-table-as-output" id="toc-providing-a-data-table-as-output" class="nav-link" data-scroll-target="#providing-a-data-table-as-output">Providing a data table as output</a></li>
255
-
<li><ahref="#creating-a-plot" id="toc-creating-a-plot" class="nav-link" data-scroll-target="#creating-a-plot">Creating a plot</a></li>
256
-
<li><ahref="#interacting-with-plots" id="toc-interacting-with-plots" class="nav-link" data-scroll-target="#interacting-with-plots">Interacting with plots</a>
255
+
<li><ahref="#creating-a-plot" id="toc-creating-a-plot" class="nav-link" data-scroll-target="#creating-a-plot">Creating a plot</a>
257
256
<ulclass="collapse">
257
+
<li><ahref="#interacting-with-plots" id="toc-interacting-with-plots" class="nav-link" data-scroll-target="#interacting-with-plots">Interacting with plots</a></li>
<p>Shiny has some native data table functions, however using the <code>DT</code> package is recommended as it supports additional data table features. When you load <code>DT</code> it will mask the base Shiny functions <code>dataTableOutput()</code> with <code>DTOutput()</code> and <code>renderDataTable()</code> with <code>renderDT()</code>. In order to use the <code>DT</code> package, we will need to load it with:</p>
330
330
<divclass="cell">
331
331
<divclass="sourceCode cell-code" id="cb1"><preclass="sourceCode r code-with-copy"><codeclass="sourceCode r"><spanid="cb1-1"><ahref="#cb1-1" aria-hidden="true" tabindex="-1"></a><spanclass="fu">library</span>(DT)</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
<h2class="anchored" data-anchor-id="creating-a-plot">Creating a plot</h2>
397
+
<sectionid="creating-a-plot" class="level1">
398
+
<h1>Creating a plot</h1>
399
399
<p>Creating plots is an essential skill for being able to create apps in Shiny, and it is exciting because there are so many ways in which you can enhance the visualization. Let’s begin with first demonstrating static plots using the <code>mtcars</code> dataset again. We will be using <code>ggplot2</code>, which is part of the <code>tidyverse</code> package, so we will need to load <code>tidyverse</code>:</p>
400
400
<divclass="cell">
401
401
<divclass="sourceCode cell-code" id="cb5"><preclass="sourceCode r code-with-copy"><codeclass="sourceCode r"><spanid="cb5-1"><ahref="#cb5-1" aria-hidden="true" tabindex="-1"></a><spanclass="fu">library</span>(tidyverse)</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
@@ -477,12 +477,12 @@ <h2 class="anchored" data-anchor-id="creating-a-plot">Creating a plot</h2>
477
477
<p><em>Hint: You will need to set <code>x = "factor(cyl)"</code> in order for the <code>aes_string()</code> function to treat <code>cyl</code> as a column coming from the <code>mtcars</code> dataset rather than looking for a variable in your R environment called <code>cyl</code>.</em></p>
<h2class="anchored" data-anchor-id="interacting-with-plots">Interacting with plots</h2>
483
482
<p>While the above plot was interesting for being able to select various metrics to plot, it lacked an ability to interact with the actual data points on the graph. For example, if we saw an outlier, how could we try to identify the specific data point. In the section below we will discuss methods that we can use to actually <strong>interact with the data points on our plots</strong>.</p>
<p>The first way that we can interact with a plot is by clicking a point on the plot. The syntax for this is a bit interesting because it has an <code>input</code> buried within an <code>Output</code> function.</p>
<p>Instead of clicking on points in your plot, you can instead hover over them and identify more information. In order to do this, we need to tweak the UI side of the app.</p>
<p>The last way that you can make your plots interactive is with brushing. Perhaps you notice a cluster of points in one part of your scatter plot that you’d like to investigate further. Brushing allows you to <strong>use a rectangle to select the points that you would like to interact with</strong>. We need a make a few changes to our UI to accommodate brushing:</p>
<spanid="cb17-46"><ahref="#cb17-46" aria-hidden="true" tabindex="-1"></a>Shiny has some native data table functions, however using the <spanclass="in">`DT`</span> package is recommended as it supports additional data table features. When you load <spanclass="in">`DT`</span> it will mask the base Shiny functions <spanclass="in">`dataTableOutput()`</span> with <spanclass="in">`DTOutput()`</span> and <spanclass="in">`renderDataTable()`</span> with <spanclass="in">`renderDT()`</span>. In order to use the <spanclass="in">`DT`</span> package, we will need to load it with:</span>
<spanid="cb17-125"><ahref="#cb17-125" aria-hidden="true" tabindex="-1"></a>Modify the app we just made which prints our output to a table to use <spanclass="in">`selectInput()`</span> menu instead of <spanclass="in">`checkboxGroupInput()`</span> in order to choose which column(s) we would like to see in our output table. </span>
<spanid="cb17-130"><ahref="#cb17-130" aria-hidden="true" tabindex="-1"></a>Creating plots is an essential skill for being able to create apps in Shiny, and it is exciting because there are so many ways in which you can enhance the visualization. Let's begin with first demonstrating static plots using the <spanclass="in">`mtcars`</span> dataset again. We will be using <spanclass="in">`ggplot2`</span>, which is part of the <spanclass="in">`tidyverse`</span> package, so we will need to load <spanclass="in">`tidyverse`</span>:</span>
<spanid="cb17-222"><ahref="#cb17-222" aria-hidden="true" tabindex="-1"></a>While the above plot was interesting for being able to select various metrics to plot, it lacked an ability to interact with the actual data points on the graph. For example, if we saw an outlier, how could we try to identify the specific data point. In the section below we will discuss methods that we can use to actually **interact with the data points on our plots**.</span>
<spanid="cb17-226"><ahref="#cb17-226" aria-hidden="true" tabindex="-1"></a>The first way that we can interact with a plot is by clicking a point on the plot. The syntax for this is a bit interesting because it has an <spanclass="in">`input`</span> buried within an <spanclass="in">`Output`</span> function. </span>
<spanid="cb17-298"><ahref="#cb17-298" aria-hidden="true" tabindex="-1"></a>Instead of clicking on points in your plot, you can instead hover over them and identify more information. In order to do this, we need to tweak the UI side of the app.</span>
<spanid="cb17-355"><ahref="#cb17-355" aria-hidden="true" tabindex="-1"></a>The last way that you can make your plots interactive is with brushing. Perhaps you notice a cluster of points in one part of your scatter plot that you'd like to investigate further. Brushing allows you to **use a rectangle to select the points that you would like to interact with**. We need a make a few changes to our UI to accommodate brushing:</span>
@@ -838,7 +838,7 @@ <h1>Input and Output Practical</h1>
838
838
<spanid="cb1-43"><ahref="#cb1-43" aria-hidden="true" tabindex="-1"></a>This app let's us select the columns that we would like to plot and then allows us to use a brush on our plot select an area of points that we are interested in evaluating.</span>
0 commit comments