gadenbuie / garrickadenbuie-com Goto Github PK
View Code? Open in Web Editor NEWMy personal website
Home Page: https://www.garrickadenbuie.com
My personal website
Home Page: https://www.garrickadenbuie.com
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 reference(s) to iris
from the following files.
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
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
https://fediscience.org/@adriangadientbruegger/111824287848446513
Dear #Quarto #rstats users: I’m trying to write my first custom template/ extension. In some examples I looked at there are #css and #scss files. Can anyone explain me what their purpose and difference is? What should I put in which of them? Links to tutorials / documentation are highly welcomed!
.content {
margin-left: 17rem; /* fix this */
margin-right: 4rem;
}
The graph
observe({
I("observe block name")
})
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)
https://twitter.com/tjmahr/status/1090241734708219904
Are there any other color-tweeting bots out there?
fs::dir_info()
returns tibbles that can be passed right into {dplyr}: https://twitter.com/johncassil/status/1103730081934004225examples_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)
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
Hey Garrick:
Been a while. Some issues with MC Test Analysis PDF file output.
Several people are using the program.
Thanks!
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)
ggnetwork::theme_void()
with ggplot2::theme_void()
content/blog/2018/2018-08-24-costcoricebag.Rmd
with cached rtweet datadeps.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'
For Presentable at useR!2021 I...
slides/01-intro/index.Rmd
<url>/slides/01-intro/
without having to write <url>/slides/01-intro/01-intro.html
xaringan::inf_mr("slides/01-intro/index.Rmd", cast_from = "slides")
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.
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.)
I think I forgot to include a folder of assets
.contact-list li {
display: inline-block;
width: 25px;
}
.contact-list {
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-between;
}
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")
})
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.
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
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>
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
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
--preserve-tabs
output:
html_document:
pandoc_args: "--preserve-tabs"
Use tabs by default by gadenbuie · Pull Request #7 · gadenbuie/grkstyle
feat: Follow RStudio indentation settings by default · gadenbuie/grkstyle@ce5cedc
grk_style_*()
text, file, directory and package styling functions will now
follow the tabs or spaces settings from the RStudio project file. You can
choose this setting in the Code Editing panel of the Project Options settings.
Added grk_reindent_auto_*()
to automatically re-indent text, file,
directory or package code according to the RStudio project file setting (or
the grkstyle.use_tabs
global R option).
https://support.rstudio.com/hc/en-us/articles/200526207-Using-RStudio-Projects
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?
These are fun ideas I want to work on but I didn't want to hold up pushing out the new theme
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
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
Explaining
#' @includeRmd man/fragments/topic.Rmd
which wasn't around when I wrote the first article.
https://www.garrickadenbuie.com/blog/dry-vignette-and-readme/
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.
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.
I'm using Featherlight for image lightboxes, but it depends on jQuery and is, AFAICT, the only thing on the blog that requires jQuery
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_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")
)
})
Hi,
I've noticed that there is a typo for the link of the website your useR2021 tutorial :
https://github.com/gadenbuie/garrickadenbuie-com/blob/main/content/talk/presentable-user2021/index.md?plain=1#L25
Is there a parameter that can be used to set whether posts are truncated or not in the homepage using your modified Hyde theme?
inspired by https://community.rstudio.com/t/best-practices-for-version-controlled-shiny-modules/29506/11 and using gadenbuie/shinyThings as an example.
<hr>
Good for collaborating with devops folks.
# A non-knitr example
with_show_query <- function(code) {
sql <- sprintf(
"\n\n<details><summary>SQL for previous query</summary>\n\n```sql\n%s\n```\n\n</details>\n\n",
dbplyr::remote_query(code)
)
print(code)
knitr::asis_output(sql)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.