UCSB-MEDS / shiny-workshop

(ARCHIVED) A hands-on coding workshop on how to build a shiny app
3 stars 0 forks source link

Running list of ideas for things to expand/include for Shiny workshop winter 2023 #5

Closed samanthacsik closed 1 year ago

samanthacsik commented 2 years ago

January 20 & 27 from 9:00am - 3:00pm

Day 1 (work only with palmerpenguins, lterdatasampler data; will have one single-file shiny app and one two-file shiny app by end of day)

Day 2 (import data tbd; should have one(?) shinydashboard by the end of the day, and possibly added themes to shiny apps from day 1)

samanthacsik commented 2 years ago

DON'T INCLUDE

Not all fontawesome icons are available for use with shiny -- here's list of icons to use as of now https://fontawesome.com/v4/icons/

samanthacsik commented 2 years ago

Debugging options: https://shiny.rstudio.com/articles/debugging.html

samanthacsik commented 2 years ago

ADDED TO RESOURCES SLIDE

General shiny resources: https://debruine.github.io/shinyintro/index.html Shiny UI editor: https://rstudio.github.io/shinyuieditor/

samanthacsik commented 2 years ago

ADDED TO RESOURCES SLIDE

Using fontawesome icons requires a fontawesome kit -- see here: https://www.r-bloggers.com/2022/09/r-shiny-fontawesome-icons-how-to-use-them-in-your-dashboards/ (must be type tag$head)

jamiecmontgomery commented 1 year ago

Have not watched this but may be helpful Beyond DataViz: How to Improve the UI/UX of Your Shiny Apps: https://www.crowdcast.io/e/shiny-apps-UX-UI-design/register

samanthacsik commented 1 year ago

ADDED TO RESOURCES SLIDE

increasing app efficiency: https://www.r-bloggers.com/2021/06/speeding-up-r-shiny-the-definitive-guide/

samanthacsik commented 1 year ago

ADDED TO THEMING SECTION

Styling with CSS & Sass: https://www.rstudio.com/resources/rstudioglobal-2021/styling-shiny-with-css-and-sass-and-speeding-up-shiny-apps/

3 ways to add CSS styling:

  1. add styling directly to tags (don't use lots of these! easy to lose track of in large projects, can't resuse the same rules easily in other elements, hard to keep consistent, hard to implement large changes)

    # can add a `style` attribute to any html `tags` used in app -- let's you add CSS elements that affect that specific statement
    fluidPage(
    tags$h1("My application", 
                  style = "font-weight: 500; color: #4d3a7e"))
    )
  2. add css to your header (a little bitter; allows code to be reused by using selectors; styles cannot be cached (i.e. saving them for future usage when you reopen the app later) since we're still declaring styles in the code)

    ui <- fluidPage(
    tags$head(
      tags$style(HTML("
       @import ulr('my-font.url'),
        h1 {
           font-weight: 500;
           color: #4d3a7e;
     }
    ") # END style
    ) # END head
    ) # END fluidPage
  3. add style sheets inside the www directory (ideal; can be cached, all styling in one spot, multiple files can be included and allow some structure, stylesheet can be applied to multiple applications, CSS can get very complicated in large projects)

    ui <- fluidPage(
    tags$head(
      tags$link(rel = "stylesheet", type = "text/css", href = "styles.css")
    ) # END head
    ) # END fluidPage

Improving with Sass

There is a {sass} package! The sass() function takes a sass string or file and returns a string of compiled CSS. (though I'm not sure I'll get into using the package since MEDS students have already been primed with CSS/Sass). A comparison:

Using the R package

library(sass)
sass(input = "
  $size: 50%;
  foo { margin: $size * .33; }
")

Writing sass

foo {
  margin: 16.5%;
}
samanthacsik commented 1 year ago

ADDED TO UX/UI SECTION

From https://engineering-shiny.org/ux-matters.html

samanthacsik commented 1 year ago

ADDED TO FINAL SECTION

Words of Wisdom (include somewhere in slide deck):

samanthacsik commented 1 year ago

Note for self on how to compile Sass to CSS -- deleting this file since I just learned you can do this more succinctly in global.R, but wanted to keep for reference:

library(sass)

sass(
  input = sass_file("R/my_sass_styles.scss"),
  #cache_options = sass_cache_options(FALSE),
  options = sass_options(
    output_style = "compressed",
    source_map_embed = TRUE),
  output = "two-file-app/www/my_sass_styles.css"
)
samanthacsik commented 1 year ago

Things to clean up: