Moved to jcheng5/elmer-assistant
https://speakerdeck.com/jcheng5/shiny-x-ai
- Video input and audio spinner controls: {shinymedia}, for R and Python
- Video assistant example app
- R version: source
Experimental function to concatenate lots of HTML dependencies' JavaScript files into one single one.
A number of caveats apply:
- Strict mode: Many JavaScript files contain
"use strict";
at the top of the file. This causes slightly different behavior in the JS engine. If the concatenated JS files have different expectations regarding strict mode, there could be problems. - Hosted scripts: This script does not attempt to concatenate JS files that are hosted on CDNs. Instead, they're left in their original form. It's possible that files we do concatenate, either assume that a CDN-hosted script is loaded before it itself is, or, the opposite.
combine_js
has a parameter that lets you decide whether to put the combined script first or last, there's no way for us to decide automatically (assuming there's even a right answer). - ES6 modules: We leave
type="module"
alone, because for ES6 modules the file boundarie
library(shiny) | |
library(crew) | |
library(promises) | |
library(bslib) | |
run_task <- function(model, n, delay_secs) { | |
Sys.sleep(delay_secs) | |
model(n) | |
} |
# Live demo at https://shinylive.io/py/app/#code=NobwRAdghgtgpmAXGKAHVA6VBPMAaMAYwHsIAXOcpMAMwCdiYACABQEkAZJgSxlWLpkmbGFADmcADoRe-QUwgBXPtiZQAzgtTTZAoSQA2A9dnXTp9Rk3UALbhFW75dOFEJluANzh4mLgI4WDMy29tgYcAAeqC7qmk5C9qiKZL4uEAAmcHS+itzmStwYSSkA+jTcBnAAFJK0lVL4THUi4nBMFVV1AJTSecUQyWSl6gbcWXS1YDaKjb51ABKz1nY0ZHW+AAy+AEwArHtbvRAFAALpE1hG65lwNCvca3AZ1d2I0kyfTADETBzEUAyTDINnavDaHy+4IkTAAvMJRBIMMRUJRqgFqiUyBhOjVut1gJsALrAOoZKBkNAUmx1IndDAkCDeQTVADkACUAOIAIVZxy+zQgAt+AGFSMyhCCwYj2mRiAplDg1HQ6FBVDQBExRDJkgYKdxSJDPtC4KVBnCtBgoCq1ZiZfyvkaeDLSjZ1J4LYMrTbsNVgIZjKYMHQxAAjUpy13u6qobiROAGQlEgD0+0OTFj8cTAEYU2nfJmE8AdnmDt0OprCwYeEKTWbMLEbGgagBabO+ADM3TpBWFTAAyqshDMpEKoS63Z5gIgtkSLXa2lGpzOmMSmABqJiYwYpDAj15MZNMNP4pgAUiY2adTtF4uyQgW-YAakxQ24ANbA+Vc7lOush0NPUwa1VV9f1iCMOgTHUPd3QjYhSgAmM4yLYkCxQnMiXQrNizpCs6AzDCa2dRdJx7MdPhvJh2TgWxmzUTJrEIKAqiYRRUC-Y8Dj-F0AMQ2im1RIF4QXCRELDYMBObUTTS9OjUXLAAqLi9npDQyGwVFqi9PJyAADgdSiKJ+JgxSZe8FRUZVQNfD9OPYLhWgkHjF2IFIhgtJy4BxYIQNtf8w34+TnmOJ0XDIRQ6FrF03LIIZpDAABfIkgA | |
from PIL import Image | |
import nump |
from shiny import App, reactive, render, ui, module | |
from shiny.session import Session | |
from contextlib import redirect_stdout, redirect_stderr | |
import asyncio | |
from shiny_console import Console, console_ui, console_server | |
# == Example usage ======================================= | |
app_ui = ui.page_fluid( |
library(shiny) | |
library(bslib) | |
library(future) | |
library(promises) | |
future::plan(future::multisession) | |
ui <- page_sidebar( | |
sidebar = sidebar( | |
numericInput("x", "x", 5), |
Drop ratelimit.py
into your app directory to use in your own Shiny for Python app. See app.py
for an example of these decorators in action.
Why is this a gist instead of a PR? Because to implement this "properly" for Shiny for Python, this would need to be beefed up to include type annotations, support for async, and unit/integration tests, which would all be more effort than this has taken so far. (To be clear, we want to do all that, but in the meantime, here's this gist.)
(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)
assign("msg", local({ | |
i <- 0 | |
function(url, ...) { | |
i <<- i + 1 | |
on.exit(i <<- i - 1) | |
if (i > 1) { | |
message("reentrancy detected!") | |
return("reentrancy detected!") | |
} | |
cat("") # Calls R_ProcessEvents() |