Skip to content

Instantly share code, notes, and snippets.

@garrettgman
Created March 27, 2014 17:43
Show Gist options
  • Save garrettgman/9813525 to your computer and use it in GitHub Desktop.
Save garrettgman/9813525 to your computer and use it in GitHub Desktop.
A lightweight example of permissions based on authorization. Note, I would need to actually collect user ids and see if they are authorized. For now, just toggle authorized to TRUE or FALSE in line 4 of server.R.
library(shiny)
library(ggplot2)
authorized <- TRUE
shinyServer(function(input, output, session) {
if (authorized) {
data <- iris
p <- qplot(Sepal.Width, Sepal.Length, data = iris, color = Species)
output$ui <- renderUI({
navbarPage(
title = 'Permissions',
tabPanel('Data', dataTableOutput('ex1')),
tabPanel('Graph', plotOutput('ex2')),
tabPanel('Authorized users only', h3('Only users with permission will see this tab')))
})
} else {
data <- iris[ , -5]
p <- qplot(Sepal.Width, Sepal.Length, data = iris)
output$ui <- renderUI({
navbarPage(
title = 'Permissions',
tabPanel('Data',
h4("Login to see a species column"),
dataTableOutput('ex1')),
tabPanel('Graph',
h4("Login to see clusters"),
plotOutput('ex2'))
)
})
}
output$ex1 <- renderDataTable(data, options = list(iDisplayLength = 10))
output$ex2 <- renderPlot({
print(p)
})
})
library(shiny)
shinyUI(
uiOutput('ui')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment