Skip to content

Instantly share code, notes, and snippets.

@vnijs
vnijs / server.R
Last active August 29, 2015 14:08 — forked from ptoche/server.R
# server.R
library("shiny")
shinyServer(
function(input, output, session) {
# Debug Area
output$Console <- renderUI({
@vnijs
vnijs / server.R
Last active August 29, 2015 14:08 — forked from Athospd/server.R
library(shiny)
library(magrittr)
shinyServer(function(input, output, session) {
#__________________________________________________________________________________
# The main named list that will be used in many other tasks.
listN <- reactiveValues()
#__________________________________________________________________________________
library(DBI)
library(RSQLite)
library(readr)
library(dplyr)
#=========================================================================
# Read a CSV file in chunks and stuff into a database.
#
# Note: This is proof-of-concept code only.
# It should work OK, but there are no guarantees.
@vnijs
vnijs / gist:8c47f4810873c8738756
Last active August 29, 2015 14:20
impute NAs
dat <- data.frame(x = rep(1:3,2),
y = c(3,1,NA,3,NA,6))
dat_org <- dat
ind <- complete.cases(dat)
model <- lm(y ~ x, data = dat[ind,])
dat$res <- NA
dat[ind,"res"] <- model$res
library(dplyr); library(httr); library(rvest)
addr <- "Big Ben"
GET("http://maps.google.com/maps/api/geocode/xml",
query = list(address = addr)) %>%
content() %>%
html_nodes(xpath = "//location//lat | //location//lng") %>%
html_text() %>%
setNames(c("lng", "lat"))
@vnijs
vnijs / batch2sqlite.R
Last active August 30, 2021 07:00
Reading a csv file into an sqlite database in chunks
library(dplyr)
library(readr)
library(DBI)
library(RSQLite)
read.csv2sqlite <- function(csv_file, sqlite_file, table_name, batch_size = 10000) {
## establish a connection to the database
condb <- dbConnect(SQLite(), sqlite_file)
@vnijs
vnijs / cc.Rmd
Created June 8, 2015 21:44
Cold call list
---
output: html_document
runtime: shiny
---
``` {r, echo=FALSE}
library(knitr)
suppressMessages(library(dplyr))
rady_class <- c("heroins")
```
@vnijs
vnijs / server.R
Last active August 29, 2015 14:23 — forked from jcheng5/server.R
shinyServer(function(input, output, session) {
# On startup, read the URL parameter
queryParams <- parseQueryString(isolate(session$clientData$url_search))
if ('tab' %in% names(queryParams))
updateTabsetPanel(session, 'tabset', selected = paste0('tab', queryParams[['tab']]))
})
@vnijs
vnijs / server.R
Last active February 5, 2023 07:14
Example of selectize drag-and-drop in Shiny 0.12.2.9000 or higher
library(shiny)
library(DT)
dat <- mtcars
shinyServer(function(input, output, session) {
output$ui_view_vars <- renderUI({
vars <- colnames(dat)
## using selectizeInput with drag_drop and DT
@vnijs
vnijs / .tmux.conf
Created December 26, 2018 18:41 — forked from CSaratakij/.tmux.conf
Tmux's Config that's very close to i3wm (Setting with an idea of using tmux without x-server)
# Config that is very close to a i3 window manager's keybinding.
set -s escape-time 0
setw -g aggressive-resize on
# First remove *all* keybindings
unbind-key -a
# List keys
bind-key ? list-keys