Skip to content

Instantly share code, notes, and snippets.

@trestletech
Last active July 10, 2020 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trestletech/7807393 to your computer and use it in GitHub Desktop.
Save trestletech/7807393 to your computer and use it in GitHub Desktop.
Shiny app used for debugging Shiny Server Pro Auth
library(shiny)
shinyServer(function(input, output, session) {
output$shinyVer <- reactive({
packageVersion("shiny")
})
output$rmarkdownVer <- reactive({
packageVersion("rmarkdown")
})
output$username <- reactive({
session$user
})
output$env <- reactive({
list_to_string(Sys.getenv())
})
output$groups <- reactive({
session$groups
})
output$headers <- reactive({
env_to_list(session$request)
})
output$creds <- renderText({
if (!exists("HTTP_SHINY_SERVER_CREDENTIALS", envir=session$request)){
return("Not logged in")
}
get("HTTP_SHINY_SERVER_CREDENTIALS", envir=session$request)
})
output$session <- renderText({
ls(envir=session)
})
list_to_string <- function(the_list) {
cnames <- names(the_list)
allvalues <- lapply(cnames, function(name) {
item <- the_list[[name]]
if (is.list(item)) {
if (is.null(names(item))) {
paste(name, "[[", seq_along(item), "]] = ", item, sep = "", collapse = "\n")
} else {
paste(name, "$", names(item), " = ", item, sep = "", collapse = "\n")
}
} else {
paste(name, item, sep=" = ")
}
})
paste(allvalues, collapse = "\n")
}
env_to_list <- function(env){
vars <- ls(envir=env)
res <- lapply(vars, function(var){
val <- get(var, envir=env)
if (is.list(val)){
return(list_to_string(val))
} else if (is.environment(val)){
return ("<environment>")
} else{
return(val)
}
})
names(res) <- vars
list_to_string(res)
}
})
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Shiny Server Pro Auth Debugger"),
sidebarPanel(
),
mainPanel(
div("Shiny version: ", verbatimTextOutput("shinyVer")),
div("RMarkdown version: ", verbatimTextOutput("rmarkdownVer")),
div("User: ", verbatimTextOutput("username")),
div("Groups: ", verbatimTextOutput("groups")),
div("Headers: ", verbatimTextOutput("headers")),
div("Creds: ", verbatimTextOutput("creds")),
div("Session: ", verbatimTextOutput("session")),
div("Environment: ", verbatimTextOutput("env"))
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment