SlideShare a Scribd company logo
Styling your projects!
Leveraging css and r/sass in R projects
16/04/2019 | PEDRO SILVA | APPSILON DAY
Agenda
● What is css?
● Adding css to shiny
● sass vs css. Why use SASS?
● How can you use sass in r (r/sass)
● Resource list
● Bonus: Non well known selectors
What is css?
What is css (Cascading Style Sheets)?
● Describes how HTML elements are to be
displayed
● Instructions are called statements.
Statements do two things:
○ Identify the elements in an HTML document
that it affects
○ Gives the browser rules on how to draw these
elements
● It can control the layout of multiple web
pages all at once (CSS saves a lot of work!)
Adding css to shiny
Adding css to shiny
● There are 3 main ways you can add css
styling to your code:
○ Add styling directly to HTML tags
○ Add CSS to your HTML header
○ Add style sheets with the www
directory
Adding css to shiny
1. Add styling directly to HTML tags
✘ Easy to lose track of in large projects
✘ Impossible to reuse code in different tags
Adding css to shiny
2. Add CSS to your HTML header
✔ Allows code to be reused by using selectors
✘ Rules cannot be cached since we are still declaring styles in the code
Adding css to shiny
3. Add style sheets with the www directory
✔ Code can be reused
✔ Allows caching
✔ Allows multiple files to be included
✘ Still has all the limitations for CSS
SASS vs CSS
SASS vs CSS
● SASS (Systematically Awesome Style Sheets) is a pre-processor of CSS
(SASS code always compiles into CSS).
SASS CSS
Object oriented Statement oriented
Allows nesting .class { p {} } No nesting
Allows variables $var = 5 No variable declaration (yet)
Allows properties to be defined outside of
SASS objects
Code is not reusable (inside CSS)
SASS: Mixins
● A Mixin is a block of code that lets us group CSS declarations we may
reuse throughout our site.
Example, displaying an HTML element as a Flex element:
Creating a Mixin:
Using a Mixin:
SASS: Functions
● SASS allows you to use functions that can be evaluated inside elements.
Example, function that defines the width of an element:
Generated CSS:
SASS: Loops
● Code can also be generated in a loop:
Generated CSS:
How can you use sass in r?
(r/sass)
How can you use sass in r (r/sass)
● Use a library!
● r/sass implements a CSS preprocessor, letting R developers use SASS to
generate dynamic style sheets.
● sass() can take a SASS string or file and returns a string of compiled CSS
main.scss
config.scss
Resources
● SASS vignette
https://rstudio.github.io/sass/articles/sass.html
● R/SASS Repository
https://github.com/rstudio/sass
● Basics on CSS
https://www.w3schools.com/css/default.asp
● Dinamic CSS generation in R
https://gallery.shinyapps.io/sass-theme/
appsilon.com
Questions?
BONUS: Selectors
you might not know
about
Bonus: Selectors
* Targets EVERY element on the page
X[attribute="foo"] {} Targets elements with a specific attribute
X ~ Y and X + Y Targets Y elements that have a sibling X:
X ~ Y {} Y elements that have an X before them.
X + Y {} Y elements that have an X IMMEDIATELY before.
X:first-of-type {} and X:last-of-type {} First or last X in a container
X:not(selector) X that is not also selector
Bonus: Selectors
X:nth-of-type(condition) Elements in a specific positions inside their container.
Condition can be a few different values:
odd or even will target all odd or even elements
x:nth-of-type(2) will target elements on a specific position
an + b a is a cycle size, n is a counter (starts at 0), and b is an offset value:
x:nth-of-type(3n+0) elements whose index is a multiple of 3
x:nth-of-type(4n+1) every 4th element starting at the first one
Online calculator: https://css-tricks.com/examples/nth-child-tester/

More Related Content

Similar to Styling your projects! leveraging css and r sass in r projects

The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
jackchenvlo
 
SCSS Implementation
SCSS ImplementationSCSS Implementation
SCSS Implementation
Amey Parab
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
Stefan Bauer
 
Sass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by ShafeeqSass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by Shafeeq
DignitasDigital1
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
kavi806657
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
 
Rational HATS and CSS
Rational HATS and CSSRational HATS and CSS
Rational HATS and CSS
Strongback Consulting
 
The sass way - Yatendra Bhardwaj
The sass way - Yatendra BhardwajThe sass way - Yatendra Bhardwaj
The sass way - Yatendra Bhardwaj
Yatendra Bhardwaj
 
Get Started With Tailwind React and Create Beautiful Apps.pdf
Get Started With Tailwind React and Create Beautiful Apps.pdfGet Started With Tailwind React and Create Beautiful Apps.pdf
Get Started With Tailwind React and Create Beautiful Apps.pdf
RonDosh
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
SURYANARAYANBISWAL1
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS Tricks
Andolasoft Inc
 
Css training tutorial css3 & css4 essentials
Css training tutorial css3 & css4 essentialsCss training tutorial css3 & css4 essentials
Css training tutorial css3 & css4 essentials
QA TrainingHub
 
CSS Interview Questions for Fresher and Experience
CSS Interview Questions for Fresher and Experience CSS Interview Questions for Fresher and Experience
CSS Interview Questions for Fresher and Experience
Hitesh Kumar
 
Srijan presentation on CSS
Srijan presentation on CSSSrijan presentation on CSS
Srijan presentation on CSS
Shashank Merothiya
 
Make your CSS beautiful again
Make your CSS beautiful againMake your CSS beautiful again
Make your CSS beautiful again
spannerspace Hales
 
Css and its future
Css and its futureCss and its future
Css and its future
Alex Bondarev
 
Revamp Your Stylesheet
Revamp Your StylesheetRevamp Your Stylesheet
Revamp Your Stylesheet
Gary Homidas
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
Authoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & SassAuthoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & Sass
chriseppstein
 

Similar to Styling your projects! leveraging css and r sass in r projects (20)

The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
 
SCSS Implementation
SCSS ImplementationSCSS Implementation
SCSS Implementation
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
 
Sass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by ShafeeqSass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by Shafeeq
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Rational HATS and CSS
Rational HATS and CSSRational HATS and CSS
Rational HATS and CSS
 
The sass way - Yatendra Bhardwaj
The sass way - Yatendra BhardwajThe sass way - Yatendra Bhardwaj
The sass way - Yatendra Bhardwaj
 
Get Started With Tailwind React and Create Beautiful Apps.pdf
Get Started With Tailwind React and Create Beautiful Apps.pdfGet Started With Tailwind React and Create Beautiful Apps.pdf
Get Started With Tailwind React and Create Beautiful Apps.pdf
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS Tricks
 
Css training tutorial css3 & css4 essentials
Css training tutorial css3 & css4 essentialsCss training tutorial css3 & css4 essentials
Css training tutorial css3 & css4 essentials
 
CSS Interview Questions for Fresher and Experience
CSS Interview Questions for Fresher and Experience CSS Interview Questions for Fresher and Experience
CSS Interview Questions for Fresher and Experience
 
Srijan presentation on CSS
Srijan presentation on CSSSrijan presentation on CSS
Srijan presentation on CSS
 
Make your CSS beautiful again
Make your CSS beautiful againMake your CSS beautiful again
Make your CSS beautiful again
 
Css and its future
Css and its futureCss and its future
Css and its future
 
Revamp Your Stylesheet
Revamp Your StylesheetRevamp Your Stylesheet
Revamp Your Stylesheet
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
Authoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & SassAuthoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & Sass
 

More from Appsilon Data Science

User! 2019 best practices for building shiny enterprise applications
User! 2019  best practices for building shiny enterprise applicationsUser! 2019  best practices for building shiny enterprise applications
User! 2019 best practices for building shiny enterprise applications
Appsilon Data Science
 
SCRUM in Data Science
SCRUM in Data ScienceSCRUM in Data Science
SCRUM in Data Science
Appsilon Data Science
 
Introduction to Generative Adversarial Networks (GANs)
Introduction to Generative Adversarial Networks (GANs)Introduction to Generative Adversarial Networks (GANs)
Introduction to Generative Adversarial Networks (GANs)
Appsilon Data Science
 
Successful Machine Learning projects in Fintech
Successful Machine Learning projects in FintechSuccessful Machine Learning projects in Fintech
Successful Machine Learning projects in Fintech
Appsilon Data Science
 
Making shiny shine brighter
Making shiny shine brighterMaking shiny shine brighter
Making shiny shine brighter
Appsilon Data Science
 
Tech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboardsTech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboards
Appsilon Data Science
 
Tech talk - Data Validation with assertr
Tech talk - Data Validation with assertrTech talk - Data Validation with assertr
Tech talk - Data Validation with assertr
Appsilon Data Science
 
Marek Rogala's Talk at User2017 on shiny.collections
Marek Rogala's Talk at User2017 on shiny.collectionsMarek Rogala's Talk at User2017 on shiny.collections
Marek Rogala's Talk at User2017 on shiny.collections
Appsilon Data Science
 
Scaling Shiny Apps - EARL 2017 San Francisco
Scaling Shiny Apps - EARL 2017 San Francisco Scaling Shiny Apps - EARL 2017 San Francisco
Scaling Shiny Apps - EARL 2017 San Francisco
Appsilon Data Science
 
Open Data - Rada Innowacyjności
Open Data - Rada InnowacyjnościOpen Data - Rada Innowacyjności
Open Data - Rada Innowacyjności
Appsilon Data Science
 

More from Appsilon Data Science (10)

User! 2019 best practices for building shiny enterprise applications
User! 2019  best practices for building shiny enterprise applicationsUser! 2019  best practices for building shiny enterprise applications
User! 2019 best practices for building shiny enterprise applications
 
SCRUM in Data Science
SCRUM in Data ScienceSCRUM in Data Science
SCRUM in Data Science
 
Introduction to Generative Adversarial Networks (GANs)
Introduction to Generative Adversarial Networks (GANs)Introduction to Generative Adversarial Networks (GANs)
Introduction to Generative Adversarial Networks (GANs)
 
Successful Machine Learning projects in Fintech
Successful Machine Learning projects in FintechSuccessful Machine Learning projects in Fintech
Successful Machine Learning projects in Fintech
 
Making shiny shine brighter
Making shiny shine brighterMaking shiny shine brighter
Making shiny shine brighter
 
Tech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboardsTech Talk - Overview of Dash framework for building dashboards
Tech Talk - Overview of Dash framework for building dashboards
 
Tech talk - Data Validation with assertr
Tech talk - Data Validation with assertrTech talk - Data Validation with assertr
Tech talk - Data Validation with assertr
 
Marek Rogala's Talk at User2017 on shiny.collections
Marek Rogala's Talk at User2017 on shiny.collectionsMarek Rogala's Talk at User2017 on shiny.collections
Marek Rogala's Talk at User2017 on shiny.collections
 
Scaling Shiny Apps - EARL 2017 San Francisco
Scaling Shiny Apps - EARL 2017 San Francisco Scaling Shiny Apps - EARL 2017 San Francisco
Scaling Shiny Apps - EARL 2017 San Francisco
 
Open Data - Rada Innowacyjności
Open Data - Rada InnowacyjnościOpen Data - Rada Innowacyjności
Open Data - Rada Innowacyjności
 

Recently uploaded

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 

Recently uploaded (20)

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 

Styling your projects! leveraging css and r sass in r projects

  • 1. Styling your projects! Leveraging css and r/sass in R projects 16/04/2019 | PEDRO SILVA | APPSILON DAY
  • 2. Agenda ● What is css? ● Adding css to shiny ● sass vs css. Why use SASS? ● How can you use sass in r (r/sass) ● Resource list ● Bonus: Non well known selectors
  • 4. What is css (Cascading Style Sheets)? ● Describes how HTML elements are to be displayed ● Instructions are called statements. Statements do two things: ○ Identify the elements in an HTML document that it affects ○ Gives the browser rules on how to draw these elements ● It can control the layout of multiple web pages all at once (CSS saves a lot of work!)
  • 6. Adding css to shiny ● There are 3 main ways you can add css styling to your code: ○ Add styling directly to HTML tags ○ Add CSS to your HTML header ○ Add style sheets with the www directory
  • 7. Adding css to shiny 1. Add styling directly to HTML tags ✘ Easy to lose track of in large projects ✘ Impossible to reuse code in different tags
  • 8. Adding css to shiny 2. Add CSS to your HTML header ✔ Allows code to be reused by using selectors ✘ Rules cannot be cached since we are still declaring styles in the code
  • 9. Adding css to shiny 3. Add style sheets with the www directory ✔ Code can be reused ✔ Allows caching ✔ Allows multiple files to be included ✘ Still has all the limitations for CSS
  • 11. SASS vs CSS ● SASS (Systematically Awesome Style Sheets) is a pre-processor of CSS (SASS code always compiles into CSS). SASS CSS Object oriented Statement oriented Allows nesting .class { p {} } No nesting Allows variables $var = 5 No variable declaration (yet) Allows properties to be defined outside of SASS objects Code is not reusable (inside CSS)
  • 12. SASS: Mixins ● A Mixin is a block of code that lets us group CSS declarations we may reuse throughout our site. Example, displaying an HTML element as a Flex element: Creating a Mixin: Using a Mixin:
  • 13. SASS: Functions ● SASS allows you to use functions that can be evaluated inside elements. Example, function that defines the width of an element: Generated CSS:
  • 14. SASS: Loops ● Code can also be generated in a loop: Generated CSS:
  • 15. How can you use sass in r? (r/sass)
  • 16. How can you use sass in r (r/sass) ● Use a library! ● r/sass implements a CSS preprocessor, letting R developers use SASS to generate dynamic style sheets. ● sass() can take a SASS string or file and returns a string of compiled CSS
  • 18. Resources ● SASS vignette https://rstudio.github.io/sass/articles/sass.html ● R/SASS Repository https://github.com/rstudio/sass ● Basics on CSS https://www.w3schools.com/css/default.asp ● Dinamic CSS generation in R https://gallery.shinyapps.io/sass-theme/
  • 20. BONUS: Selectors you might not know about
  • 21. Bonus: Selectors * Targets EVERY element on the page X[attribute="foo"] {} Targets elements with a specific attribute X ~ Y and X + Y Targets Y elements that have a sibling X: X ~ Y {} Y elements that have an X before them. X + Y {} Y elements that have an X IMMEDIATELY before. X:first-of-type {} and X:last-of-type {} First or last X in a container X:not(selector) X that is not also selector
  • 22. Bonus: Selectors X:nth-of-type(condition) Elements in a specific positions inside their container. Condition can be a few different values: odd or even will target all odd or even elements x:nth-of-type(2) will target elements on a specific position an + b a is a cycle size, n is a counter (starts at 0), and b is an offset value: x:nth-of-type(3n+0) elements whose index is a multiple of 3 x:nth-of-type(4n+1) every 4th element starting at the first one Online calculator: https://css-tricks.com/examples/nth-child-tester/