Skip to content

Instantly share code, notes, and snippets.

View nanxstats's full-sized avatar

Nan Xiao nanxstats

View GitHub Profile
@nanxstats
nanxstats / shiny-file-input-area.R
Created April 18, 2022 01:50
Shiny file input area (Bootstrap 5)
fileInputArea <- function(inputId, label, multiple = FALSE, accept = NULL,
width = NULL, buttonLabel = "Browse...", placeholder = "No file selected") {
restoredValue <- restoreInput(id = inputId, default = NULL)
# Catch potential edge case - ensure that it's either NULL or a data frame.
if (!is.null(restoredValue) && !is.data.frame(restoredValue)) {
warning("Restored value for ", inputId, " has incorrect format.")
restoredValue <- NULL
}
@nanxstats
nanxstats / shiny-bs5-switches.R
Created April 14, 2022 04:26
Bootstrap 5 Switches for Shiny
switchInput <- function(inputId, label, value = FALSE, disabled = FALSE, width = NULL) {
value <- shiny::restoreInput(id = inputId, default = value)
inputTag <- htmltools::tags$input(id = inputId, type = "checkbox", role = "switch", class = "form-check-input")
if (!is.null(value) && value) {
inputTag$attribs$checked <- NA
}
if (!is.null(disabled) && disabled) {
inputTag$attribs$disabled <- NA
}
htmltools::tags$div(
@nanxstats
nanxstats / dt-news-list.R
Created April 9, 2022 07:08
Paginated news list with DT/DataTables
# Generate mock data -----------------------------------------------------------
set.seed(42)
k <- 100
df <- data.frame(
title = unlist(purrr::map2(
.x = stringr::word(stringi::stri_rand_lipsum(k), start = 1, end = 10),
.y = rep("#", k),
.f = function(.x, .y) as.character(htmltools::tags$a(.x, href = .y))
)),
time = as.POSIXct(unlist(
@nanxstats
nanxstats / tnum.R
Last active January 19, 2022 05:42
Test native font stack on tabular numbers
library(knitr)
library(htmltools)
library(webshot2)
df <- mtcars[2:7, c("mpg", "disp", "drat", "wt", "qsec")]
rownames(df) <- NULL
colnames(df) <- NULL
tnum <- function(font, title, output) {
tags$html(
@nanxstats
nanxstats / ggplot2-shiny-responsive.R
Last active January 11, 2023 16:24
ggplot2 responsive panels with shiny and facet_wrap() https://d.cosx.org/d/423852
library("shiny")
library("ggplot2")
ui <- fluidPage(
plotOutput("plot_responsive")
)
server <- function(input, output, session) {
output$plot_responsive <- renderImage(
{
@nanxstats
nanxstats / rbind-saved-reply.md
Created May 6, 2021 20:07
rbind support saved reply

We have configured the rbind subdomain you requested. Please:

  1. Add the rbind subdomain in your Netlify account as the custom domain to your site, as is shown below. Simply use your subdomain.rbind.io as the record, no www needed.

  1. There might be messages saying "DNS verification failed" or "check DNS configuration" on Netlify after adding the rbind
@nanxstats
nanxstats / release_checklist_nanxstats.md
Last active February 11, 2025 00:23
Nan's simple R package release checklist

First release

  • Proof read Title: and Description: and ensure they are informative
  • Check that all exported functions have @returns and @examples
  • Check that Authors@R: includes a copyright holder (role 'cph')
  • Review extrachecks
  • usethis::use_cran_comments() (optional)

Prepare for release

@nanxstats
nanxstats / release_checklist.md
Last active May 4, 2021 17:51
R package release checklist from usethis::use_release_issue but it's just copy-pastable Markdown
@nanxstats
nanxstats / greta-bayesian-lasso.R
Last active December 23, 2020 02:02
Bayesian lasso with greta, compared to lasso and msaenet
# https://nanx.me/blog/post/bayesian-lasso-with-greta/
# generate synthetic data ------------------------------------------------------
library("msaenet")
n <- 500
p <- 1000
pnz <- 10

TensorFlow Installation

I have to admit that it is painful to install TensorFlow, especially when you need a specific version. That's why I took some notes.

My general experience is that the pip approach has many potential issues on its path, mostly due to the dependency version issues from NVIDIA's libraries. The conda approach is much easier as it bundles everything.

This is written on 2020-11-27. The applicability might change in the future.

GPU Driver