Created
March 19, 2016 20:40
-
-
Save explodecomputer/bed7c2b249a689cd40ea to your computer and use it in GitHub Desktop.
shiny minimal examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- bootstrapPage( | |
selectizeInput('foo', choices = NULL, label="Species") | |
) | |
server <- function(input, output, session) | |
{ | |
updateSelectizeInput(session, 'foo', choices = state.name, server = TRUE) | |
} | |
runApp(shinyApp(ui, server)) | |
ui <- bootstrapPage( | |
radioButtons('show', "Show", choices=c("1", "2")), | |
uiOutput('uiout') | |
) | |
fn1 <- function(session) | |
{ | |
updateSelectizeInput(session, 'foo', choices = letters, server = TRUE) | |
selectizeInput('foo', choices = NULL, label="Species", multiple=TRUE) | |
} | |
fn2 <- function(session) | |
{ | |
updateSelectizeInput(session, 'bar', choices = as.character(1:20000), server = TRUE) | |
selectizeInput('bar', choices = NULL, label="Other", multiple=TRUE) | |
} | |
server <- function(input, output, session) | |
{ | |
output$uiout <- renderUI({ | |
switch(input$show, | |
"1" = fn1(session), | |
"2" = fn2(session) | |
) | |
}) | |
} | |
runApp(shinyApp(ui, server)) | |
library(shiny) | |
library(shinydashboard) | |
library(googleAuthR) | |
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email")) | |
options("googleAuthR.webapp.client_id" = "906514199468-1jpkqgngur8emoqfg9j460s47fdo2euo.apps.googleusercontent.com") | |
options("googleAuthR.webapp.client_secret" = "I7Gqp83Ku4KJxL9zHWYxG_gD") | |
ui <- dashboardPage( | |
dashboardHeader(title = "Example login"), | |
dashboardSidebar( | |
sidebarMenu(id = "tabs", | |
menuItem("Login", tabName = "dashboard", icon = icon("smile-o")), | |
menuItemOutput("logged_in") | |
) | |
), | |
dashboardBody( | |
tabItems( | |
tabItem(tabName = "dashboard", | |
box( | |
loginOutput("loginButton"), | |
uiOutput("logininfo") | |
) | |
), | |
tabItem(tabName = "logged_in_page", | |
box(title = "Logged in") | |
) | |
) | |
) | |
) | |
user_info <- function(){ | |
f <- gar_api_generator("https://www.googleapis.com/oauth2/v1/userinfo", | |
"GET", | |
data_parse_function = function(x) x | |
) | |
f() | |
} | |
server <- function(input, output, session) | |
{ | |
access_token <- reactiveAccessToken(session) | |
output$loginButton <- renderLogin(session, access_token()) | |
if(is.null(shiny::isolate(access_token()))) | |
{ | |
output$logininfo <- renderUI({NULL}) | |
} else { | |
get_user_info <- reactive({ | |
with_shiny(f = user_info, | |
shiny_access_token = access_token() | |
) | |
}) | |
output$logininfo <- renderUI({ | |
x <- get_user_info() | |
HTML('<p>Logged in as <strong>', x$name, '</strong> (', x$email, ')</p>') | |
}) | |
output$logged_in <- renderMenu({ | |
menuItem("Logged in", tabName = "logged_in_page") | |
}) | |
} | |
} | |
runApp(shinyApp(ui, server), port=4018) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment