This snippet shows how you could use later to create an API that can be called on a background thread, to perform an arbitrary task on the main R thread, and return the result to the background thread. The background thread blocks until the result is returned from the main R thread.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before running this script, set the LDAP_PASSWORD environment variable in | |
// the shell. You can do this without echoing the password by running: | |
// | |
// read -s LDAP_PASSWORD && export LDAP_PASSWORD | |
// | |
// You'll also need to modify the variable definitions at the top of this file. | |
// == BEGIN configuration variables =============== | |
var url = "ldap://adtest.rstudio.com/dc=adtest,dc=rstudio,dc=com"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base_task_iterator <- function(should_continue, iter_body) { | |
if (should_continue()) { | |
iter_body() | |
later::later(~base_task_iterator(should_continue, iter_body)) | |
} | |
invisible() | |
} | |
while_task_iterator <- function(cancelExpr, whileExpr, func) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://builder.r-hub.io/file/5e5a06074fba4784a9f164e3970a2ead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggplot2) | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("dataset", "Dataset", c("cars", "pressure", "mtcars")), | |
uiOutput("input_ui") | |
), | |
mainPanel( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(dplyr) | |
library(ggplot2) | |
dedupe <- function(r) { | |
x <- reactiveVal(isolate(r())) | |
o <- observe({ | |
x(r()) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snippet shinymod | |
${1:name}UI <- function(id) { | |
ns <- NS(id) | |
tagList( | |
${0} | |
) | |
} | |
${1:name} <- function(input, output, session) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# WARNING: This sketch does not make proper use of the "state" parameter. | |
# Doing so usually involves using cookies, which can be done with the | |
# Rook package but I have not done that here. If you choose to use this | |
# approach in production, please check the state parameter properly! | |
APP_URL <- if (interactive()) { | |
# This might be useful for local development. If not, just hardcode APP_URL | |
# to the deployed URL that you'll provide a few lines below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Configure delays using the following constants. | |
# before worker starts responding to listeners | |
STARTUP_DELAY_SECS = 0 | |
# time to load ui.R (before first "/" response only) | |
UI_INIT_DELAY_SECS = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
convertToSF <- function(df, id = "id", group = "group") { | |
# Extract the non-polygon data. | |
data <- df %>% | |
group_by_(id) %>% | |
do(head(., 1)) %>% | |
.[,setdiff(names(.), c("long", "lat", "order", "hole", "piece", "group"))] | |
# Extract the shapes. I don't know if this does the right |