Skip to content

Instantly share code, notes, and snippets.

@nirguk
nirguk / MiraiExtendedTask.R
Last active August 9, 2024 13:24
Idea on how shiny::ExtendedTask might be subclassed to support cancel/early stop of tasks which are mirai backed
# credit Joe Cheng / jcheng5 / https://gist.github.com/jcheng5/1283baec96c05a65778d931a8b7c7314
# for mirai cancel concept
library(shiny)
library(mirai)
library(promises)
library(bslib)
library(R6)
# SETUP ####
# Define a subclass that inherits from ExtendedTask
MiraiExtendedTask <- R6::R6Class(
@jcheng5
jcheng5 / README.md
Last active November 13, 2024 05:46
Accepting POST requests from Shiny

Accepting POST requests from Shiny

(This post was motivated by a talk by @jnolis at CascadiaRConf 2021)

Recent versions of Shiny have an undocumented feature for handling POST requests that are not associated with any specific Shiny session. (Note that this functionality is missing our normal level of polish; it's a fairly low-level hook that I needed to make some things possible, but doesn't make anything easy.)

In a nutshell, it works by replacing your traditional ui object with a function(req), and then marking that function with an attribute indicating that it knows how to handle both GET and POST:

library(shiny)
@stla
stla / groupedBarChartBinding.js
Last active May 28, 2019 14:12
amcharts 4 grouped bar chart for Shiny
var groupedBarChartBinding = new Shiny.InputBinding();
$.extend(groupedBarChartBinding, {
find: function(scope) {
return $(scope).find(".amGroupedBarChart");
},
getValue: function(el) {
return $(el).data("data");
},
getType: function(el) {
@jcheng5
jcheng5 / app.R
Last active February 3, 2024 17:34
Using OAuth2 with Shiny
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.
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / app.R
Last active March 21, 2023 15:16
Shiny dynamic UI - observers & lapply
# An example based on http://shiny.rstudio.com/articles/dynamic-ui.html
library(shiny)
ui = basicPage(
fluidRow(
actionButton(inputId = "add_buttons", label = "Add 5 Buttons")
),
uiOutput("more_buttons") # this is where the dynamically added buttons will go.
)
@bborgesr
bborgesr / reactives-in-loops.R
Created March 5, 2017 19:20
How to use reactives in loops. What works, what doesn't and why.
# -------------------------------------------------------------------
# ------------------ REACTIVES INSIDE FOR LOOPS ---------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# --- EXAMPLE 1: this works fine, because there are no reactives in -
# --- the for lopp --------------------------------------------------
# -------------------------------------------------------------------
library(shiny)
@hrbrmstr
hrbrmstr / app.R
Created January 23, 2017 20:06 — forked from leonawicz/app.R
Use custom local image files as icons in a Shiny Dashboard value box
#
# This Shiny web application demonstrates the use of custom image files
# in place of icons for value boxes in Shiny Dashboard by overriding two
# functions:
#
# 'icon' from the shiny package and 'valueBox' from the shinydashboard package.
#
# Each function adds minimal, specific additional handling of image files.
# Note: A custom css file must also be included so that value boxes can
# display the icons. For that reason, do not expect images in place of icons to
@leonawicz
leonawicz / app.R
Last active March 14, 2021 06:27
Use custom local image files as icons in a Shiny Dashboard value box
#
# This Shiny web application demonstrates the use of custom image files
# in place of icons for value boxes in Shiny Dashboard by overriding two
# functions:
#
# 'icon' from the shiny package and 'valueBox' from the shinydashboard package.
#
# Each function adds minimal, specific additional handling of image files.
# Note: A custom css file must also be included so that value boxes can
# display the icons. For that reason, do not expect images in place of icons to
@tbadams45
tbadams45 / app.R
Created August 4, 2016 21:14
Using conditionalPanel inside of Shiny Modules
testUI <- function(id, label = "CSV file") {
# Create a namespace function using the provided id
ns <- NS(id)
tagList(
selectizeInput(
ns('mySelect'), 'Test Select', choices = state.name,
options = list(
placeholder = 'Please select an option below',
@tchakravarty
tchakravarty / nginx.conf
Created June 13, 2016 11:03
nginx.conf to proxy Shiny server in Docker container
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {