Skip to content

Instantly share code, notes, and snippets.

Avatar

Dean Attali daattali

View GitHub Profile
@daattali
daattali / bad.R
Created Mar 5, 2020
using reactivity correctly
View bad.R
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 / accordion_reprex
Last active Jun 20, 2019 — 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.
View accordion_reprex
makeReactiveTrigger <- function() {
rv <- shiny::reactiveValues(a = 0)
list(
depend = function() {
rv$a
},
trigger = function() {
rv$a <- shiny::isolate(rv$a + 1)
}
)
View ListDynamicCountryByAsset.json.txt
[{"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
daattali / rmd_to_md_pandoc.Rmd
Last active Feb 13, 2018
How to get pandoc 2+ to retain HTML tags in markdown?
View rmd_to_md_pandoc.Rmd
## foo `bar`
hello
```
x <- 5
```
<p align="center">test</p>
View postgresql.R
# Connecting using RPostgreSQL works
library(RPostgreSQL)
con <- dbConnect(dbDriver("PostgreSQL"),
host = "localhost",
dbname = "postgres",
user = "postgres",
password = password,
port = 5432)
@daattali
daattali / towebgl.R
Created Nov 6, 2017
plotly toWebGL issues
View towebgl.R
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)
@daattali
daattali / sqlserver.R
Last active Oct 19, 2017
connecting to SQL Server external vs local
View sqlserver.R
# production
dbConnect(
RSQLServer::SQLServer(),
server = config$server,
database = config$database,
properties = list(
user = config$uid,
password = config$pwd
)
)
View plotlyclicklasso.R
# 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)
View plotlycurvenumber.R
# 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!
library(plotly)
library(shiny)
ui <- fluidPage(
plotlyOutput("plot")
)
@daattali
daattali / layout_change.R
Created May 13, 2017
Change the width of the main panel depending on what tab is open
View layout_change.R
library(shiny)
ui <- fluidPage(
shinyjs::useShinyjs(),
# 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",