{"componentChunkName":"component---src-components-tutorials-js","path":"/tutorials/sass-in-shiny/","result":{"data":{"markdownRemark":{"html":"<h2>Contents</h2>\n<ol>\n<li><a href=\"#about\">Why would I need this?</a></li>\n<li>\n<p><a href=\"#work\">How does this work?</a></p>\n<ol>\n<li><a href=\"#work-about\">What is a CSS preprocessor and what does it do?</a></li>\n<li><a href=\"#work-install\">Installing node, npm and sass</a></li>\n<li><a href=\"#work-project\">Setting up your project directory</a></li>\n<li><a href=\"#work-file\">Creating the package.json file</a></li>\n<li>\n<p><a href=\"#work-scripts\">Defining the build Scripts</a></p>\n<ol>\n<li><a href=\"#work-scripts-shiny\">Adding a Shiny script</a></li>\n<li><a href=\"#work-scripts-dev\">Adding a Dev script</a></li>\n<li><a href=\"#work-scripts-tmux\">Using tmux</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li><a href=\"#further-considerations\">What do I need to know before implementing this into my app?</a></li>\n<li><a href=\"#run\">How do I run the example?</a></li>\n</ol>\n<!-- endexcerpt -->\n<span id=\"about\" />\n<h2>Why would I need this?</h2>\n<p>If your shiny applications have a lot styling or you have branding guidelines to follow, you may find that your projects have one large css file or that you are loading many css files in your app. A single css file can become difficult to manage and loading many files which can result in poor load times. The css file may also have outdated or unused css that may go unnoticed if there are hundreds or thousands of styles.</p>\n<p>There are plenty of discussions and recommendations for best practices for writing css in the frontend space and these concepts can be applied to shiny app development. One recommendation that can greatly improve shiny app development is using a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CSS_preprocessor\">css preprocessor</a>. </p>\n<p>In this tutorial, I will provide a few steps for getting started with the css preprocessor <a href=\"https://sass-lang.com/\">SASS</a> in shiny applications. I will not focus so much on how to write scss, but more on how to set up sass. If you want to learn how to use sass, I would recommend starting with the official <a href=\"https://sass-lang.com/documentation\">documentation</a>.</p>\n<span id=\"work\" />\n<h2>How does this work?</h2>\n<p>This section will provide information on starting a new project and show how to integrate shiny and sass. This section will discuss the following.</p>\n<ol>\n<li>Installing nodeJS, npm, and sass</li>\n<li>Setting up your project directory</li>\n<li>Creating the package.json file</li>\n<li>Defining the build scripts</li>\n</ol>\n<p>Before I dive into the tutorial, I'll provide some background on SASS. </p>\n<span id=\"work-about\" />\n<h3>What is a CSS preprocessor and what does it do?</h3>\n<p>What does a css preprocessor do exactly? CSS Preprocessors are an extension to css that allow you to write css with many helpful features such as nesting, modules, functions, variables, and much more. Behind the scenes, the CSS preprocessor are compiling your code into normal css. Let's take a look at an example. </p>\n<p>Let's say I have a section (<code>&#x3C;section></code>) that has a light background. Within the section, there is a heading (<code>&#x3C;h2></code>) and there are several paragraphs (<code>&#x3C;p></code>). We may want the paragraphs to be lighter in color than the section headings. Sometimes a paragraph may have a link (<code>&#x3C;a></code>) and the link must be red and also have a thick red underline. In addition to paragraphs, some sections may also have an image (<code>&#x3C;img></code>)that have a fixed width. Let's say that I want to set the width of the first image in each section to 300px. So, what would the css look like for all of these elements?</p>\n<p><strong>Using CSS</strong></p>\n<p>In css, you might write the styles in the following way.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">section</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">padding</span><span class=\"token punctuation\">:</span> 16px<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">background-color</span><span class=\"token punctuation\">:</span> #f6f6f6<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">section h2</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 21pt<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> #252525<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">section p</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 16pt<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> #3f454b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">section p a</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> red<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">text-decoration</span><span class=\"token punctuation\">:</span> none<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">-webkit-box-shadow</span><span class=\"token punctuation\">:</span> inset 0 -2px 0 0 red<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">box-shadow</span><span class=\"token punctuation\">:</span> inset 0 -2px 0 0 red<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">section img</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">width</span><span class=\"token punctuation\">:</span> 100px<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">section img:first-child</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">width</span><span class=\"token punctuation\">:</span> 300px<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This is a simple example, but there are some things that could be improved and prep for future styles. For example, what if we wanted to use the link color in other places? It is possible to copy and paste the value where we need it, but what if you were to change the color again? It would be nice to assign the color to a variable which could be called anywhere we like. This would eliminate the need to update the values manually and may result in inconsistent color values.</p>\n<p>What about the box shadow? Is there a better way to write it? <code>-webkit-</code> is a vendor prefix so that other browsers or older versions can interpret properties correctly. It would be nice if we could write this once.</p>\n<p>The other issue is the way child elements are selected. Notice how all child elements start with <code>section</code>. It would nice if there was a way we could type this once. This may seem like it is not a major issue as this example is fairly small, but it can become difficult to manage when you are working with longer class names, when class names change, when there are many nested elements with child elements, adding in hover states, generating pseudo-elements, and much more.</p>\n<p><strong>Using SCSS</strong></p>\n<p>Let's rewrite this using the css preprocessor <a href=\"https://sass-lang.com\">SASS</a>. There are a few <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CSS_preprocessor\">css preprocessors</a> available, but I will mainly focus on using sass; specifically, <code>.scss</code> files. You can use <code>.sass</code> files, but the indentation rules are hard to work with. I prefer <code>.scss</code> files as the syntax rules follow normal css.</p>\n<p>Using the list of complaints above, here is how to address these issues using sass.</p>\n<ol>\n<li><strong>Rewrite common values as variables:</strong> In sass, variables are defined with <code>$variable_name: somevalue</code>. For example, let's say we want to specify the color blue <code>$blue: #5177b8;</code>.</li>\n<li><strong>Use mixins to for box shadow:</strong> Using SASS <a href=\"https://sass-lang.com/documentation/at-rules/mixin\">mixins</a>, we can create a function that returns the css markup for a box shadow based on an input value. Mixins can be defined by using <code>@mixin mymixin($somevalue){ some-property: $somevalue }</code> and then used anywhere by using <code>@include mymixin(\"hello, world\")</code></li>\n<li><strong>Use SASS Nesting:</strong> The greatest thing about preprocessors is <a href=\"https://sass-lang.com/documentation/style-rules#nesting\">nested selector paths</a>. This eliminates the need to type the same paths each time you want to style a child element. This is incredibly helpful when adding styles for hover states and for <code>nth</code> child rules.</li>\n</ol>\n<p>Here is the same css, but rewritten using scss variables, mixins, and nested selectors.</p>\n<div class=\"gatsby-highlight\" data-language=\"scss\"><pre class=\"language-scss\"><code class=\"language-scss\"><span class=\"token comment\">// variables: colors</span>\n<span class=\"token property\"><span class=\"token variable\">$heading-color</span></span><span class=\"token punctuation\">:</span> #252525<span class=\"token punctuation\">;</span>  <span class=\"token comment\">// dark gray</span>\n<span class=\"token property\"><span class=\"token variable\">$text-color</span></span><span class=\"token punctuation\">:</span> #3f454b<span class=\"token punctuation\">;</span>     <span class=\"token comment\">// medium gray</span>\n<span class=\"token property\"><span class=\"token variable\">$bg-color</span></span><span class=\"token punctuation\">:</span> #f6f6f6<span class=\"token punctuation\">;</span>       <span class=\"token comment\">// light gray</span>\n<span class=\"token property\"><span class=\"token variable\">$link-color</span></span><span class=\"token punctuation\">:</span> red<span class=\"token punctuation\">;</span>\n<span class=\"token property\"><span class=\"token variable\">$link-shadow</span></span><span class=\"token punctuation\">:</span> inset 0 -2px 0 0 <span class=\"token variable\">$link-color</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// thick link underline</span>\n\n<span class=\"token comment\">// mixin for boxshadow</span>\n<span class=\"token keyword\">@mixin</span> <span class=\"token function\">box-shadow</span><span class=\"token punctuation\">(</span><span class=\"token variable\">$value</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token property\">-webkit-box-shadow</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$value</span><span class=\"token punctuation\">;</span>\n    <span class=\"token property\">box-shadow</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$value</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// nested styles</span>\n<span class=\"token selector\">section </span><span class=\"token punctuation\">{</span>\n    <span class=\"token property\">padding</span><span class=\"token punctuation\">:</span> 16px<span class=\"token punctuation\">;</span>\n    <span class=\"token property\">background-color</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$bg-color</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token selector\">h2 </span><span class=\"token punctuation\">{</span>\n        <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 21pt<span class=\"token punctuation\">;</span>\n        <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$heading-color</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token selector\">p </span><span class=\"token punctuation\">{</span>\n        <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> 16pt<span class=\"token punctuation\">;</span>\n        <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$text-color</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token selector\">a </span><span class=\"token punctuation\">{</span>\n            <span class=\"token property\">color</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$link-color</span><span class=\"token punctuation\">;</span>\n            <span class=\"token property\">text-decoration</span><span class=\"token punctuation\">:</span> none<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">@include</span> <span class=\"token function\">box-shadow</span><span class=\"token punctuation\">(</span><span class=\"token variable\">$link-shadow</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token selector\">img </span><span class=\"token punctuation\">{</span>\n        <span class=\"token property\">width</span><span class=\"token punctuation\">:</span> 100px<span class=\"token punctuation\">;</span>\n\n        <span class=\"token selector\"><span class=\"token parent important\">&amp;</span>:first-child </span><span class=\"token punctuation\">{</span>\n            <span class=\"token property\">width</span><span class=\"token punctuation\">:</span> 300px<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This may seem like more work, but it's much easier in the long run. Since scss allows for nested selectors, you do not need to write long selector paths. Let the preprocessor handle that. All values are rewritten as variables which can now be reused anywhere we want. If the values were to be changed, we do not need to worry about finding all instances of the value and changing them manually (say goodbye to <code>ctrl + f</code>).</p>\n<p>Another advantage of using a preprocessor is that you now have a self contained module for section elements. You can save this above code into it's own file (e.g., <code>section.scss</code>) and then use it in other projects. When you view shiny apps as a series components and modules (even css), it makes the development process much easier resulting in consistent UI across applications. This approach is useful when you are developing multiple applications for an organization that has strict branding guidelines. </p>\n<span id=\"work-install\" />\n<h3>Installing Node, Npm, and SASS</h3>\n<p>Let's focus on getting sass working with shiny. You will need to install a few tools to do so: nodejs, npm, and sass. </p>\n<p>First, we will install node and npm. Npm and Node are installed together so visit the <a href=\"https://nodejs.org/en/download/\">nodejs downloads page</a> and download the latest installer. If you aren't sure if you have these tools installed or would like to confirm that they were installed correctly, run the following commands.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> -v\nnode -v</code></pre></div>\n<p>Each command will print the verison number. If no errors are thrown, then you can install SASS using npm.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> -g sass</code></pre></div>\n<p>To confirm the installation of SASS, run the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">sass -v</code></pre></div>\n<p>If you encounter any errors installing these tools, visit the official installation documentation for more information.</p>\n<ul>\n<li><a href=\"https://docs.npmjs.com/downloading-and-installing-node-js-and-npm\">Installing nodejs and npm</a></li>\n<li><a href=\"https://sass-lang.com/install\">SASS installation page</a></li>\n</ul>\n<span id=\"work-project\" />\n<h3>Setting up your project directory</h3>\n<p>In your shiny project, create the <code>www</code> folder and a subfolder which will be used to place all the sass files. I'm calling the subfolder <code>css</code> for simplicity.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">myshinyapp /\n    + www /\n        + css /</code></pre></div>\n<p>Next, create the desired scss files. My preferred method is to have a master sass file (I am naming <code>index.R</code>), several component-based files, and a variables file. Each component-based file contains the styles for a specific element such as a navigation bar, the footer of an app, or an input widget. I use the variables file to define the app's color palette, font sizes, or other values that may be used in other components. I use the master sass file to load all component-base files and write styles for specific elements. I like this approach as it is easier to manage several smaller files than one large file. Most of my projects will have a variation of the following structure.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">css /\n    _base.scss          <span class=\"token comment\"># similar to normalize.css</span>\n    _dropdown.scss      <span class=\"token comment\"># for a dropdown menu</span>\n    _footer.scss        <span class=\"token comment\"># page footer</span>\n    _navbar.scss        <span class=\"token comment\"># navigation bar</span>\n    _page.scss          <span class=\"token comment\"># all page content (i.e., within &lt;main> and &lt;section>)</span>\n    _variables.scss     <span class=\"token comment\"># colors, font sizes, etc.</span>\n    index.scss          <span class=\"token comment\"># load all other files and one off styles</span></code></pre></div>\n<span id=\"work-file\" />\n<h3>Creating the package.json file</h3>\n<p>Next, create a package.json file. This file contains information about your application such as author, app description, licenses, list of dependencies, build scripts, and more. You can create this file in the terminal using the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> init</code></pre></div>\n<p>This will present a handful of prompts where you can enter information about the project. Some information may be found automatically and some questions have default values. This process should take a minute or two. If you do not know, you can always edit the file later.</p>\n<span id=\"work-scripts\" />\n<h3>Defining the build scripts</h3>\n<p>Now that the package.json file, is created we can add a few build scripts. For example, starting the shiny server and starting sass. We can create an alias for a command so we do not have to type it over again. </p>\n<p>In the package.json file, there is an entry called \"scripts\". There may already be entry for <code>tests</code> which can be remove if you do not have any test scripts to run. On a new line, we will create a new script for starting the sass server. The syntax for the sass command is <code>sass --watch input:output</code>. In the section \"Setting up your project directory\", we created a master scss file called <code>index.scss</code>. This is the entry point that sass will use compile the css. Here's the sass script.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"sass\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"sass --watch www/css/index.scss:www/css/styles.css\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In many of my projects, I like to output a compressed (or minified) css file. To do this, add the option: <code>--style compressed</code> at the end.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"sass\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"sass --watch www/css/index.scss:www/css/styles.min.css --style compressed\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To start sass, you can run the following command (either in a terminal or in an RStudio terminal tab).</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> run sass</code></pre></div>\n<p>If you are using git for version control, it is a good idea to add the sass cache folder to the gitignore file</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echo &quot;.sass-cache/&quot; &gt;&gt; .gitignore</code></pre></div>\n<p>Over the last year or so, I find that I am working more with other IDEs (sublime text, vscode) than in Rstudio; especially for shiny development. This is personal preference so the next few sections mostly apply to working outside of RStudio. </p>\n<span id=\"work-scripts-shiny\" />\n<h4>Adding a Shiny script (optional)</h4>\n<p>Instead of starting the shiny server in RStudio, you can create a script that launches the shiny server. I like to run apps on port <code>1234</code> so I do not have to find the port number each time I start the shiny server.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"shiny\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Rscript -e 'shiny::runApp(launch.browser=FALSE, port=1234)'\"</span>\n    ...\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To start the shiny server using this script, type the following command in the terminal.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> run shiny</code></pre></div>\n<span id=\"work-scripts-dev\" />\n<h4>Adding a Dev Script (optional)</h4>\n<p>If you decide to use the shiny script, you may also want a script that starts the sass server and shiny server. To do this, create a new script that starts both scripts.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"sass\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"sass --watch www/css/index.scss:www/css/styles.min.css --style compressed\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"shiny\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Rscript -e 'shiny::runApp(launch.browser=FALSE, port=1234)'\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"dev\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"npm run shiny &amp; npm run sass\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To start both servers, type the following command in the terminal.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> run dev</code></pre></div>\n<p>If you have scripts that run sequentially, use <code>&#x26;&#x26;</code>. Otherwise, <code>&#x26;</code> runs commands in parallel. This applies to unix-based users. There are other npm packages availabe for windows users. See the <a href=\"https://www.npmjs.com/package/concurrently\">concurrently package</a> on npm.</p>\n<span id=\"work-scripts-tmux\" />\n<h4>Using tmux (optional, but recommended)</h4>\n<p>There are some drawbacks to using the <code>dev</code> script. It may become too cluttered if there are sass errors and shiny errors. I'm finding that I use the <code>dev</code> script less. Instead, I use a terminal multiplexer called <a href=\"https://github.com/tmux/tmux\">tmux</a>. Tmux allows you to start multiple terminals in a single screen. Here's a screenshot of the demo shiny app using tmux.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 600px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/e1644da71e5c4bb5857c330a070351b0/10ab7/tmux.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 61.33333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAAsTAAALEwEAmpwYAAABzUlEQVQoz4VSyW7UQBDt1e1l7G5vY81iYCJFSUaJEOIEFz6COSDu4ANCtOCbyBwiPjCxZyrVjhMlGo84PJXV5Xr16lWRZaE/Tcv4HxfyrxTi2vO8bRiG2yAMMD4i3MZx3Eel1Fb56iEifN+/DgKH4Abz74kx5icChBBACBkFZQzSLIciL8BoA+7/NE1Ba91HJAMpJXDOv5I0zb7N5jVUVXWLHe+QoD0AZa3JTDuri7Za5G1R5i2StSjC5V3NrWvMGPtMwnDSmLR03Tocdz+ukoEKPYgLBVHqgY/fqOYx72p2A+EGI2lQGaxWqw79GCek9KgdB4TYqXEe5HneoQ9HCBkI9AgL/k+IJI1bCKW0G5KjhNq4ZWjAbUOSJE+IomiPE+7clChug9PQZig8SkgZBzNsNcsywPPoPRwu46VCxlmDpEDJk8JDULZH0j0dybk3rN85jmEp9Pug5G5QeYjeDtodzT+cl+PYkNlc/jgtSpinb0DEGSol0Ct+DlwGY+5MKASKg1K4HHyLPQmncQSvFgtY1jXoJPlCztb++uPrkz/ny3e//GltOaWWC2HRo5cQ3CKp1RPPTmJpuZS2jEL7oczt2/WFvby6+l1Npyf3OdTfvjgma+oAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"tmux screenshot\"\n        title=\"tmux screenshot\"\n        src=\"/static/e1644da71e5c4bb5857c330a070351b0/0a47e/tmux.png\"\n        srcset=\"/static/e1644da71e5c4bb5857c330a070351b0/8a4e8/tmux.png 150w,\n/static/e1644da71e5c4bb5857c330a070351b0/5a46d/tmux.png 300w,\n/static/e1644da71e5c4bb5857c330a070351b0/0a47e/tmux.png 600w,\n/static/e1644da71e5c4bb5857c330a070351b0/1cfc2/tmux.png 900w,\n/static/e1644da71e5c4bb5857c330a070351b0/c1b63/tmux.png 1200w,\n/static/e1644da71e5c4bb5857c330a070351b0/10ab7/tmux.png 1552w\"\n        sizes=\"(max-width: 600px) 100vw, 600px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>In this arrangement, the left pane is used for running various commands. The top right pane is used for running the sass server and the shiny server is running in the bottom right. I use this setup more than dev script as each process can be run independently and it's easier to identify which tool is throwing an error. </p>\n<span id=\"futher-considerations\" />\n<h2>What do I need to know before implementing this into my app?</h2>\n<p>You may also want to use a css autoprefixer in your applications as this would eliminate the need to write vendor prefixes yourself. I will likely create a new tutorial or update this one to demonstrate this. Stay tuned for more information!</p>\n<span id=\"run\" />\n<h2>How do I run the example?</h2>\n<p>The example application can be run by typing the following commands.</p>\n<div class=\"gatsby-highlight\" data-language=\"r\"><pre class=\"language-r\"><code class=\"language-r\">install.packages<span class=\"token punctuation\">(</span><span class=\"token string\">\"shiny\"</span><span class=\"token punctuation\">)</span>\nshiny<span class=\"token operator\">::</span>runGitHub<span class=\"token punctuation\">(</span>repo <span class=\"token operator\">=</span> <span class=\"token string\">\"shinyAppTutorials\"</span><span class=\"token punctuation\">,</span> username <span class=\"token operator\">=</span> <span class=\"token string\">\"davidruvolo51\"</span><span class=\"token punctuation\">,</span> subdir <span class=\"token operator\">=</span> <span class=\"token string\">\"sass-in-shiny\"</span><span class=\"token punctuation\">)</span></code></pre></div>","frontmatter":{"title":"Shiny and CSS Preprocessors","subtitle":"Getting started with SASS in Shiny apps","abstract":"Managing css can become difficult as projects grow and new features are added. Using a css preprocessor brings many helpful features for writing and managing css. In this tutorial, learn how to use SASS in your shiny applications.","date":"2020-01-16","updated":"2020-01-21","keywords":["css","scss"]},"fields":{"readingTime":{"minutes":12.025}}}},"pageContext":{"slug":"/tutorials/sass-in-shiny/"}},"staticQueryHashes":["63159454"]}