Title: | Shiny Apps on Crunch |
---|---|
Description: | To facilitate building custom dashboards on the Crunch data platform <https://crunch.io/>, the 'crunchy' package provides tools for working with 'shiny'. These tools include utilities to manage authentication and authorization automatically and custom stylesheets to help match the look and feel of the Crunch web application. The package also includes several gadgets for use in 'RStudio'. |
Authors: | Greg Freedman Ellis [aut, cre], Neal Richardson [aut], Jonathan Keane [aut], Gordon Shotwell [aut], Mike Malecki [aut] |
Maintainer: | Greg Freedman Ellis <[email protected]> |
License: | LGPL (>= 3) |
Version: | 0.3.4 |
Built: | 2024-11-03 03:50:51 UTC |
Source: | https://github.com/crunch-io/crunchy |
These are no longer necessary. Just use the shiny
ones and it just works.
These functions are left here for backwards compatibility.
crunchPage(...) crunchFluidPage(...) crunchFillPage(...) crunchNavbarPage(...)
crunchPage(...) crunchFluidPage(...) crunchFillPage(...) crunchNavbarPage(...)
... |
arguments passed to |
The result of fluidPage
, fillPage
or navbarPage
## Not run: crunchPage( fluidRow( column(6, selectInput("filter", label="Filter", choices=filterList, selected="All"), br(), plotOutput("funnel1", height="300"), ), column(6, selectInput("brand", label="Competitor", choices=brands, selected="Nike"), br(), plotOutput("funnel2", height="300"), ) ) ) ## End(Not run)
## Not run: crunchPage( fluidRow( column(6, selectInput("filter", label="Filter", choices=filterList, selected="All"), br(), plotOutput("funnel1", height="300"), ), column(6, selectInput("brand", label="Competitor", choices=brands, selected="Nike"), br(), plotOutput("funnel2", height="300"), ) ) ) ## End(Not run)
When using crunchyServer()
to wrap your app in Crunch authentication and
authorization, you need to wrap your UI body content inside crunchyBody()
.
crunchyBody(...)
crunchyBody(...)
... |
UI elements for your app |
This is the part that is conditionally rendered if the user is allowed.
Any UI elements you want always to show, including <head>
tags, should go
outside this function.
A uiOutput()
container into which crunchyServer()
will
conditionally render output.
crunchyPublicBody()
crunchyServer()
## Not run: shinyUI(fluidPage( tags$head( # This is content that will always be rendered tags$title("My secure app") ), crunchyBody( # This is content that only is rendered if the user is authorized fluidRow( column(6, h1("Column 1")), column(6, h1("Column 2")) ) ) )) ## End(Not run)
## Not run: shinyUI(fluidPage( tags$head( # This is content that will always be rendered tags$title("My secure app") ), crunchyBody( # This is content that only is rendered if the user is authorized fluidRow( column(6, h1("Column 1")), column(6, h1("Column 2")) ) ) )) ## End(Not run)
crunchyServer()
and crunchyBody()
allow you to protect your app with
Crunch authentication and authorization. Add these UI contents to your
shiny::shinyUI()
body to display different content for visitors who are
not authenticated with Crunch (crunchyPublicBody()
) or who are
authenticated but not authorized to access your app
(crunchyUnauthorizedBody
).
crunchyPublicBody(...) crunchyUnauthorizedBody(...)
crunchyPublicBody(...) crunchyUnauthorizedBody(...)
... |
UI elements for your app, to be conditionally rendered |
An empty string; these functions are called for their side effects of
registering the UI elements so that crunchyServer()
can render them as
appropriate.
crunchyBody()
; setCrunchyAuthorization()
for governing who is
authorized to view your app.
## Not run: # This is the example from crunchyBody(), adding these alternate bodies: shinyUI(fluidPage( tags$head( # This is content that will always be rendered tags$title("My secure app") ), crunchyBody( # This is content that only is rendered if the user is authorized fluidRow( column(6, h1("Column 1")), column(6, h1("Column 2")) ) ), crunchyPublicBody( # This is shown to visitors who are not logged into Crunch at all h1("Please log into Crunch.") ), crunchyUnauthorizedBody( # This is for Crunch users who don't meet your authorization criteria # Perhaps they don't have access to a particular dataset h1("You don't have access to this app."), tags$div("Contact [email protected].") ) )) ## End(Not run)
## Not run: # This is the example from crunchyBody(), adding these alternate bodies: shinyUI(fluidPage( tags$head( # This is content that will always be rendered tags$title("My secure app") ), crunchyBody( # This is content that only is rendered if the user is authorized fluidRow( column(6, h1("Column 1")), column(6, h1("Column 2")) ) ), crunchyPublicBody( # This is shown to visitors who are not logged into Crunch at all h1("Please log into Crunch.") ), crunchyUnauthorizedBody( # This is for Crunch users who don't meet your authorization criteria # Perhaps they don't have access to a particular dataset h1("You don't have access to this app."), tags$div("Contact [email protected].") ) )) ## End(Not run)
To make sure that users who access your shiny.crunch.io app are allowed to
access it, use crunchyServer()
instead of shiny::shinyServer()
, and wrap
your UI content inside crunchyBody()
. This will prevent anyone who is not
logged into Crunch in their browser from accessing your app.
crunchyServer(func, authz = getOption("crunchy.authorization"))
crunchyServer(func, authz = getOption("crunchy.authorization"))
func |
A |
authz |
A |
To restrict access further to only certain Crunch users, you can set an
authorization method, either by passing a server function to
the authz
argument of this function, or by calling
setCrunchyAuthorization()
.
For a simple example app using crunchyServer()
, copy
system.file("example_apps/crunchy_server/app.R", package="crunchy")
,
supply your dataset id on line 14, and run it.
Invisibly, a Shiny server function with the auth logic wrapped around
func
.
crunchyBody()
for wrapping the UI contents, crunchyPublicBody()
for specifying an alternate UI for when the user is not authenticated,
crunchyUnauthorizedBody()
for giving an alternate UI for users who are
authenticated with Crunch but not authorized to view this app, and
setCrunchyAuthorization()
for governing who is authorized to view
your app.
Open dataset selector
listDatasetGadget(...)
listDatasetGadget(...)
... |
Further arguments passed to |
A loadDataset()
call is pasted into your RStudio session
Categorical Array and Multiple Response variables can be difficult to construct without being able to investigate the available variables, and their categories. This shiny gadget lets you select subvariables from the dataset list, and ensures that those variables have consistent categories. To use the gadget you must have at least one CrunchDataset loaded into the global environment.
makeArrayGadget(env = globalenv())
makeArrayGadget(env = globalenv())
env |
the environment to run the gadget |
a valid call to makeArray()
or makeMR()
Call this to set an expression or server function to evaluate to determine whether the current user is authorized to access your app. Ideally, this is cheap to execute because it will be called repeatedly.
setCrunchyAuthorization(func)
setCrunchyAuthorization(func)
func |
A |
Invisibly, the server function. This function is called
for the side effect of setting the authorization function globally. The
function should return TRUE
if the current user is authorized.
setCrunchyAuthorization(function (input, output, session) { # Restrict to users who have crunch.io emails endsWith(email(shinyUser()()), "@crunch.io") })
setCrunchyAuthorization(function (input, output, session) { # Restrict to users who have crunch.io emails endsWith(email(shinyUser()()), "@crunch.io") })
This function wraps crunch::loadDataset()
in a
shiny::reactive()
object for use in a Shiny app. It also ensures
that the current user is authenticated with Crunch before proceeding.
shinyDataset(...)
shinyDataset(...)
... |
Arguments passed to |
A Shiny reactive
object.
## Not run: shinyServer(function(input, output, session) { ds <- shinyDataset("Your dataset name") freqs <- reactive({ fmla <- as.formula(paste("~", input$varname)) crtabs(fmla, data=ds()) }) }) ## End(Not run)
## Not run: shinyServer(function(input, output, session) { ds <- shinyDataset("Your dataset name") freqs <- reactive({ fmla <- as.formula(paste("~", input$varname)) crtabs(fmla, data=ds()) }) }) ## End(Not run)
This function returns information about the current user of the shiny app. This
is useful if you want to change the behavior of the app depending on who is
viewing the app. You can access elements of this record with crunch functions
like name()
or email().
shinyUser()
shinyUser()
A user record if the user is logged in, otherwise a character vector or error
Some potentially large operations, such as imports and exports, report
progress in the Crunch API. In an interactive R session, they print a text
progress bar. This context, which wraps shiny::withProgress()
, reports that
Crunch API progress up to the Shiny web app.
withCrunchyProgress(expr, ...)
withCrunchyProgress(expr, ...)
expr |
Code to evaluate |
... |
Additional arguments passed to |
The result of expr
## Not run: withCrunchyProgress( ds <- newDataset(df), message = "Importing..." ) ## End(Not run)
## Not run: withCrunchyProgress( ds <- newDataset(df), message = "Importing..." ) ## End(Not run)