Skip to content

Instantly share code, notes, and snippets.

View daattali's full-sized avatar

Dean Attali daattali

View GitHub Profile
daattali / bad.R
Created March 5, 2020 17:15
using reactivity correctly
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 / 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)
depend = function() {
trigger = function() {
rv$a <- shiny::isolate(rv$a + 1)
[{"CountryList": ["Austria", "Germany", "Italy", "Spain", "United Kingdom"], "Sector3": "Commercial Leases"}, {"CountryList": ["Belgium", "France", "Germany", "Ireland", "Italy", "Netherlands", "Portugal", "Spain", "United Kingdom"], "Sector3": "Residential Mortgage"}, {"CountryList": ["Belgium", "France", "Ireland", "Spain", "United Kingdom"], "Sector3": "Credit Card"}, {"CountryList": ["Belgium", "Germany", "Italy", "Portugal", "Spain"], "Sector3": "SME CLO"}, {"CountryList": ["France", "Germany", "Netherlands"], "Sector3": "Auto Leases"}, {"CountryList": ["France", "Germany", "Italy", "Netherlands", "Norway", "Portugal", "Spain", "United Kingdom"], "Sector3": "Auto Loans"}, {"CountryList": ["France", "Germany", "Italy", "Netherlands", "Portugal", "Spain", "Sweden"], "Sector3": "Consumer Loans"}, {"CountryList": ["France", "Portugal", "United Kingdom"], "Sector3": "Mixed Auto Loans and Leases"}, {"CountryList": ["Germany", "Ireland", "Italy", "Spain"], "Sector3": "Consumer and Commercial Leases"}, {"Country
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`
x <- 5
<p align="center">test</p>
# Connecting using RPostgreSQL works
con <- dbConnect(dbDriver("PostgreSQL"),
host = "localhost",
dbname = "postgres",
user = "postgres",
password = password,
port = 5432)
daattali / towebgl.R
Created November 6, 2017 20:09
plotly toWebGL issues
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)
daattali / sqlserver.R
Last active October 19, 2017 17:51
connecting to SQL Server external vs local
# production
server = config$server,
database = config$database,
properties = list(
user = config$uid,
password = config$pwd
# 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
# I'm trying to let the user select points and paint them in a certain colour, and if the user clicks on a point then paint that point a different colour.
# It looks like the pointNumber and curveNumber data that plotly returns are different for the same points. I'm not sure how curveNumber works, but to me it doesn't make sense yet :)
# Any help is appreciated!
ui <- fluidPage(
daattali / layout_change.R
Created May 13, 2017 20:16
Change the width of the main panel depending on what tab is open
ui <- fluidPage(
# You have to include this one-liner CSS
tags$style(".fullwidth { width: 100% !important; }"),
# You need to wrap the sidebarLayout() by a div() and give it an ID
div(id = "SOMEID",