Skip to content

Instantly share code, notes, and snippets.

View daattali's full-sized avatar

Dean Attali daattali

View GitHub Profile
# Clicking on a single point seems to clear the lasso selection. But the opposite is not true: doing a lasso selection still keeps the clicked point information.
# To reproduce:
# - Click a single point
# - Do a lasso selection
# - Both are currently visible
# - Click a different point
# - Now the lasso selection information is gone
# - Do a lasso selection again, both are visible again
library(shiny)
@daattali
daattali / sqlserver.R
Last active October 19, 2017 17:51
connecting to SQL Server external vs local
# production
dbConnect(
RSQLServer::SQLServer(),
server = config$server,
database = config$database,
properties = list(
user = config$uid,
password = config$pwd
)
)
@daattali
daattali / towebgl.R
Created November 6, 2017 20:09
plotly toWebGL issues
library(ggplot2)
library(plotly)
data <- data.frame(x = rnorm(20), y = runif(20), z = letters[1:20])
p <- ggplot(data, aes(x = x, y = y)) +
geom_smooth(method='lm') +
geom_point(aes(text = z)) +
scale_x_continuous(limits = c(0, 5)) +
annotate("text", label = "foo", x=1, y=1)
# Connecting using RPostgreSQL works
library(RPostgreSQL)
con <- dbConnect(dbDriver("PostgreSQL"),
host = "localhost",
dbname = "postgres",
user = "postgres",
password = password,
port = 5432)
@daattali
daattali / rmd_to_md_pandoc.Rmd
Last active February 13, 2018 05:16
How to get pandoc 2+ to retain HTML tags in markdown?
## foo `bar`
hello
```
x <- 5
```
<p align="center">test</p>
@daattali
daattali / gmailr-text.R
Last active March 30, 2018 00:02
Send a text message via email from R
library(shiny)
library(gmailr)
ui <- fluidPage(
textInput("subj", "Subject", "Schedule change"),
textInput("text", "Message"),
actionButton("btn", "Send")
)
server <- function(input, output, session) {
@daattali
daattali / accordion_reprex
Last active June 20, 2019 21:11 — forked from geebioso/accordion_reprex
This code creates deletable dynamic accordions that load a modal when they are created. The modal is triggering too many times after an accordion is deleted and then reloaded.
makeReactiveTrigger <- function() {
rv <- shiny::reactiveValues(a = 0)
list(
depend = function() {
rv$a
},
trigger = function() {
rv$a <- shiny::isolate(rv$a + 1)
}
)
@daattali
daattali / rselenium-taxonomer-1-upload.R
Last active June 24, 2019 09:00
Use RSelenium to automatically upload many FASTQ files, submit each to "full analysis" when it's ready, and download the analyzed file on Taxonomer.com
# This script uploads all the FAST files to the taxonomer server (only one file can be uploaded at a time)
# Assumes that you have RSelenium package installed and that you've got a simple selenium example to work
if (FALSE) {
fastq_files <- c(
list.files(# WHERE ARE THE FILES?, pattern = "fastq.gz$", full.names = TRUE)
)
login_password <- "" # what is my password???
library(RSelenium)
@daattali
daattali / bad.R
Created March 5, 2020 17:15
using reactivity correctly
library(shiny)
library(ggplot2)
makePlot <- function(xvar, yvar) {
ggplot(iris, aes_string(xvar, yvar)) + geom_point()
}
ui <- fluidPage(
selectInput("xvar", "X variable", choices = names(iris), selected = names(iris)[1]),
selectInput("yvar", "Y variable", choices = names(iris), selected = names(iris)[2]),
@daattali
daattali / quiet.R
Created September 25, 2015 00:35
Suppress all output from an expression, cross-platform
#' Suppress all output from an expression. Works cross-platform.
#' @param expr Expression to run.
#' @param all If \code{TRUE} then suppress warnings and messages as well;
#' otherwise, only suppress printed output (such as from \code{print} or
#' \code{cat}).
#' @keywords internal
#' @export
quiet <- function(expr, all = TRUE) {
if (Sys.info()['sysname'] == "Windows") {
file <- "NUL"