Git Product home page Git Product logo

garrickadenbuie-com's People

Contributors

cderv avatar gadenbuie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

garrickadenbuie-com's Issues

Post: screengrabs of shiny apps, automated

library(shiny)
options(shiny.autoreload = FALSE)

app <- new.env()
source(system.file("examples", "01_hello", "app.R", package = "shiny"), local = app)

ui <- tagList(
  app$ui,
  tags$script(type = "module", HTML("
import { toPng } from 'https://cdn.skypack.dev/html-to-image';

const page = document.querySelector('body .container-fluid');

function screenGrabApp (shinyEventName) {
  toPng(page)
    .then(dataURL => Shiny.setInputValue('screenshot', {event: shinyEventName, data: dataURL}))
    .catch(console.error)
}

['value', 'idle', 'outputinvalidated'].forEach(function(name) {
  $(document).on('shiny:' + name, function() { screenGrabApp(name) })
})
"))
)

server <- function(input, output) {
  app$server(input, output)

  observeEvent(input$screenshot, {
    event <- input$screenshot$event
    time <- sub("[.]", "", strftime(Sys.time(), "screenshots/%F_%H%M%OS3"))
    path <- sprintf("%s_%s.png", time, event)
    message(path)
    data <- sub("data:image/png;base64,", "", input$screenshot$data, fixed = TRUE)
    data <- base64enc::base64decode(data)
    writeBin(data, path)
  })
}

dir.create("screenshots", showWarnings = FALSE)
shinyApp(ui, server, options = list(port = 6543))

Remove references to iris

Remove reference(s) to iris from the following files.

References




basic_iris_plot <- basic_iris_plot + scale_color_pomological()




pomological_iris <- basic_iris_plot + theme_pomological_fancy()


paint_pomological(pomological_iris, res = 110) %>%





podcasts

Cropping Images

Hi there @gadenbuie, I am trying to reproduce your latest blog post at my end here but I am stock, after reading in the image, I get the following error when I try to call the profile. Please can you help me to resolve this ? The line that is giving me issues is below in bold. I suspect after reading in the image with magick the image is corrupted because I cannot view them

library(magick)
library(purrr)
dir.create("profiles")
photo_ids <- c("DItYlc26zVI", "bpxgyD4YYt4", "6anudmpILw4", "3dqSZidOkvs")

for (id in photo_ids) {
  download.file(
    sprintf("https://source.unsplash.com/%s", id),
    sprintf("profiles/%s.jpg", id)
  )
}

#I’ve put the photos in a profiles/ directory so that I can list the them all at once:  
fs::dir_ls("profiles")
## profiles/3dqSZidOkvs.jpg profiles/6anudmpILw4.jpg profiles/DItYlc26zVI.jpg 
## profiles/bpxgyD4YYt4.jpg

Magick with R

The first step is to use the magick package to read in our profile pictures.

profiles <- 
  fs::dir_ls("profiles") |>
  map(image_read)

profiles # **This is the line that is giving me error**
Error in magick_image_info(image) : 
  rsession-utf8.exe: Invalid geometry argument

Render_toc.R to change "font size and margin" for the word output

Dear Gadenbuie,

I am wondering how to change the "font size and margin" for the rmarkdown render? I used a word template to set-up the format, however, I find there is no way to change the font size and margin, no matter changing to the word template, neither the YAML setting. Any suggestion will be appreciated.

Thanks.

Shicheng

[Post] Make the image an actual circle

Ah I should have made that a little clearer in the post. The presentation of the image as a circle is done with CSS in the post.

In this case, since they're profile pictures, I wouldn't actually want to apply the circle to the image itself; instead I'd leave that to whatever service is using the profile image. For example, in most places Twitter uses a circular profile image but sometimes it uses a square. Some social sites might use larger or smaller circles or apply their own cropping logic, etc.

To modify the image directly to achieve the circle border, this StackOverflow post seems to be a good place to start. I haven't tried it but I think you would use image_draw() to draw a circle and then use image_composite() to overlay the circle on the image. Hope that helps!

Originally posted by @gadenbuie in #121 (reply in thread)

shiny tip: developing modules

examples_UI <- function(id) {
  ns <- NS(id)
  # ... module UI code ...
}
examples <- function(input, output, session) {
  # ... module Server code ...
}

# this part is the tip ----
ui <- fluidPage(
  examples_UI("example")
)
server <- function(input, output, session){
  callModule(examples, 'example')
}
shinyApp(ui, server)

Blog style revamp

  • Remove my photo from the sidebar

  • Bump font size on large width screens

  • Fix blog urls to blog/:slug instead of blog/yyyy/mm/dd/:slug and redirect old urls

  • highlight link styles

  • tweak code and results css inspired by brodie's blog

    image

MC Test Analysis

Hey Garrick:
Been a while. Some issues with MC Test Analysis PDF file output.

  1. Does not include Cronbach alpha
  2. ICC curves only shown for first 18 Qs.

Several people are using the program.
Thanks!

make blog more reproducible

install.packages("blogdown")
blogdown::install_hugo()

cran_pkgs <- c("here", "png", "ggridges", "zoo", "ggnetwork". "rtweet", "ggsci", "hrbrthemes", "showtext", "sysfonts", "plotly", "kableExtra", "syuzhet", "magick")
install.packages(cran_pkgs)

remotes <- c("gadenbuie/sqrrl", "gadenbuie/ggpomological")
remotes::install_github(remotes)
  • replace ggnetwork::theme_void() with ggplot2::theme_void()
  • Fix content/blog/2018/2018-08-24-costcoricebag.Rmd with cached rtweet data

deps.yaml

- Package: knitr
  Repository: CRAN
  Version: '1.21'
- Package: devtools
  Repository: CRAN
  Version: 2.0.1
- Package: stringr
  Repository: CRAN
  Version: 1.3.1
- Package: here
  Repository: CRAN
  Version: '0.1'
- Package: png
  Repository: CRAN
  Version: 0.1-7
- Package: ggplot2
  Repository: CRAN
  Version: 3.1.0
- Package: ggridges
  Repository: CRAN
  Version: 0.5.1
- Package: dplyr
  Repository: CRAN
  Version: 0.7.8
- Package: reshape2
  Repository: CRAN
  Version: 1.4.3
- Package: purrr
  Repository: CRAN
  Version: 0.3.0
- Package: zoo
  Repository: CRAN
  Version: 1.8-4
- Package: ggnetwork
  Repository: CRAN
  Version: 0.5.1
- Package: tidyverse
  Repository: CRAN
  Version: 1.2.1
- Package: blogdown
  Repository: CRAN
  Version: '0.10'
- Package: tibble
  Repository: CRAN
  Version: 2.0.1
- Package: rtweet
  Repository: CRAN
  Version: 0.6.8
- Package: lubridate
  Repository: CRAN
  Version: 1.7.4
- Package: glue
  Repository: CRAN
  Version: 1.3.0
- Package: ggsci
  Repository: CRAN
  Version: '2.9'
- Package: hrbrthemes
  Repository: CRAN
  Version: 0.6.0
- Package: showtext
  Repository: CRAN
  Version: '0.6'
- Package: sysfonts
  Repository: CRAN
  Version: '0.8'
- Package: scales
  Repository: CRAN
  Version: 1.0.0
- Package: hms
  Repository: CRAN
  Version: 0.4.2
- Package: rlang
  Repository: CRAN
  Version: 0.3.1
- Package: plotly
  Repository: CRAN
  Version: 4.8.0
- Package: kableExtra
  Repository: CRAN
  Version: 1.0.1
- Package: syuzhet
  Repository: CRAN
  Version: 1.0.4
- Package: sqrrl
  GithubUsername: gadenbuie
  GithubRepo: sqrrl
  GithubRef: master
  GithubSHA1: e014027842d4e260051d1e7cfe0dc5686811197d
- Package: nycflights13
  Repository: CRAN
  Version: 1.0.0
- Package: DBI
  Repository: CRAN
  Version: 1.0.0
- Package: dbplyr
  Repository: CRAN
  Version: 1.3.0
- Package: RSQLite
  Repository: CRAN
  Version: 2.1.1
- Package: ggpomological
  GithubUsername: gadenbuie
  GithubRepo: ggpomological
  GithubRef: master
  GithubSHA1: 5d0c3352aad1dbf6d29cb95d6acc53198bb299ac
- Package: readr
  Repository: CRAN
  Version: 1.3.1
- Package: magick
  Repository: CRAN
  Version: '2.0'

Post: workshop with xaringan slides and a hugo page

For Presentable at useR!2021 I...

  • Stored the slides in static/slides
    • Slides are all stored in the same base directory, which makes life a little easier when editing
    • If you have slides in subfolders
      • I prefer to store them like slides/01-intro/index.Rmd
      • That way you can go to <url>/slides/01-intro/ without having to write <url>/slides/01-intro/01-intro.html
      • You can still use infinite moon reader, but you need to call it manually: xaringan::inf_mr("slides/01-intro/index.Rmd", cast_from = "slides")
  • Created a slides/ index page with a content/slides.Rmarkdown
  • I used a make script in static/slides/make.R that honestly is overly complicated but is also called as part of the hugo build process from R/build.R

For JavaScript for Shiny Users I put slides in a separate repo and then hosted the slides at https://slides.js4shiny.com and just linked out from the main page. Again, added an index page so that you can click through to individual slides. This is also the origin of the make.R script mentioned above.

Show toc/source on small screens

Kind of annoying that you can't get to the post source unless your screen is big enough. (Less worried about the toc, but could be in an expandable details section.)

tweak sidebar links

.contact-list li {
  display: inline-block;
  width: 25px;
}

.contact-list {
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: space-between;
}

Post: downlit anything that's managed by knitr

knitr::knit_hooks$set(document = function(x) {
  frontmatter <- withr::with_tempfile("md", {
    writeLines(x, md)
    rmarkdown::yaml_front_matter(md)
  })
  z <- c(
    "---", 
    yaml::as.yaml(frontmatter),
    "---", 
    downlit::downlit_md_string(x)
  )
  paste(z, collapse = "\n")
})

Signed commits with RStudio

See rstudio issue 1865

https://grrrck.notion.site/keybase-gpg-setup-commit-signing-35333d2eb5e9492fa69846a9184fd587

I just went through setting up signed commits, in my case using a keybase GPG key. With a few additional configuration steps, it works well with RStudio.

  1. Set your git global config to sign commits using your default key

    git config --global user.signingkey <Key ID>
    git config --global commit.gpgsign true
  2. Configure gpg to use an agent for providing your password to unlock your key (I also set the default key here to make life easier)

    # ~/.gnupg/gpg.conf
    use-agent
    default-key <Key ID>
  3. Configure gpg-agent to remember your key's password for the day (8 hours or 28,800 seconds)

    # ~/.gnupg/gpg-agent.conf
    default-cache-ttl 28800
    max-cache-ttl 28800

    You may need to restart gpg-agent at this point.

    gpg-agent --daemon
    
    # if it prints a message that gpg-agent is already running...
    kill-all gpg-agent
    gpg-agent --daemon
  4. At this point, any git commit will automatically be signed using your default key. The first commit of the day will require you to enter your password, which does mean that the RStudio Git UI won't be able to sign the first commit unless you've asked gpg to sign something for you.

    To get around this, you can unlock your gpg key by signing anything at the start of your work day or whenever the 8 hour time limit runs out.

    echo "open sesame" | gpg -s > /dev/null
    # prompt for password 

[post] tabs or spaces

add a license?

Would you consider adding a license to this repo? I'm guessing that might be a lot to ask to put a blanket license for the entire website and all the code you post on it.

I'm wondering because I'd like to include your excellent cal() function in a personal R package. (https://www.garrickadenbuie.com/blog/r-console-calendar/) Or have you by chance included that code in a package somewhere with a license?

xaringan series

  • xaringan -> powerpoint
  • xaringan slides from templates
  • xaringan auto-advance/rotating slides
  • hosting xaringan slides on github/netlify
  • logos on all slides
  • xaringan with sounds on transition

Rmd hunks

Thanks again for your post about re-usable Rmd pieces @gadenbuie!

I'd have left a comment if I could, so yes you're missing out (just kidding).

Compared to your post, I now put re-usable Rmd pieces under man/rmdhunks/ see for instance https://github.com/lockedata/hubspot that passes R CMD check and whose pkgdown website looks fine.

Downsides to keeping pieces under vignettes/ : pieces not available during R CMD check, and pkgdown builds them as unnamed articles.

See also r-hub/blog#44

Idea: dplyr as a case study in API design

Very cool that Hadley kept notes about the design of dplyr in the repo and we can now look back at some of the thinking that went into the dplyr design. The current version is like a 4K resolution picture of what was then a very blurry idea. It's amazing to see the thread of thinking as he worked through those early stages and the API took form.

For example, this very very early design document https://github.com/tidyverse/dplyr/blob/a3cebb2a06cb7c1f413422cb5cff5c6ccdddf54c/notes/syntax.md

Post: picking colors for the new site

The short answer is that I used a neat tool I discovered at https://accessiblepalette.com. Here are the settings for the colors I used in my theme (the URL lets you bookmark your colors).

I'd recommend starting with one or two colors and add new shades until you have enough colors for what you need. You probably don't need as many colors as I picked. I went a little crazy and created a matching syntax highlighting style, so I needed more than a few colors.

Getting the colors out of the tool is a bit complicated. I ended up writing a little javascript to extract the colors from the page as JSON and then a little R to turn it into the CSS variables in assets/garrick-hex.scss. I should add those scripts (if I find them) to the post.

My biggest recommendation would be to pick one accent color and one text shade color. Use those base colors and their shades and tints (darker and lighter versions) throughout. Maaaaaybe add a second accent color.

In terms of implementation, I highly recommend using CSS variables to store the colors rather than SCSS variables. You can pass the CSS variables to the SCSS variables, so I went all the way and created CSS variables that correspond to the SCSS variables created by the Apero theme.

--slate-00: #0e181e;
--textColorCustom: var(--slate-00);
$textColorCustom: var(--textColorCustom);

This makes it possible to reference var(--slate-00) or var(--textColorCustom) anywhere throughout your site if you want to use those variables later. You can't do that with SCSS variables since they're compiled away and aren't available to your individual pages.

The other thing this makes possible is automatic dark and light mode using CSS variables. I need to look up the link where I learned about this and it's probably not the absolute best approach because there isn't a button on the page to toggle dark light. By using @media (prefers-color-scheme: dark) (MDN) you can override the CSS variables for the theme properties so they change on the fly when the user's operating system (or their settings) declare that they want dark or light mode.

I approached this by creating CSS variables for theme properties that are then used to set the theme's SCSS variables. Note that this literally sets the SCSS variable to the CSS variable, so that later I can change the CSS variable values for dark mode.

[Post] knitr hook for adding explainshell links to bash commands

Decorate bash chunks with a special comment next to lines you want to explain, e.g.

ssh -T [email protected] # explain

and it links the command on that line to https://explainshell.com, e.g.

Source Hook
source_hook_og <- knitr::knit_hooks$get("source")
knitr::knit_hooks$set(source = function(x, options) {
  is_bash <- identical(options$engine, "bash")
  rgx_explain <- "\\s*#\\s*explain\\s*$"
  needs_explained <- any(grepl(rgx_explain, x))
  if (!is_bash || !needs_explained) {
    return(source_hook_og(x, options))
  }
  if (length(x) == 1 && grepl("\n", x)) {
    x <- strsplit(x, "\n")[[1]]
  }
  idx_explain <- grep(rgx_explain, x)
  cmds <- sub(rgx_explain, "", x[idx_explain])
  cmds_explain <- sprintf("https://explainshell.com/explain?cmd=%s", utils::URLencode(cmds))
  x[idx_explain] <- sprintf(
    '<a href="%s" target="_blank">%s</a>',
    cmds_explain,
    cmds
  )
  sprintf(
    '\n\n<pre class="sourceCode bash"><code class="sourceCode bash">%s</code></pre>\n\n',
    paste(x, collapse = "\n")
  )
})

truncate param in Hyde theme

Is there a parameter that can be used to set whether posts are truncated or not in the homepage using your modified Hyde theme?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.