Skip to content

Instantly share code, notes, and snippets.

View shaun-jacks's full-sized avatar

Shaun Jackson shaun-jacks

  • Software Engineer, Sony Playstation
  • San Diego, CA
View GitHub Profile
@shaun-jacks
shaun-jacks / shiny-vision-ui.R
Last active February 18, 2019 06:12
UI for R Shiny Project
# This ui function holds the ui for our Shiny Vision Project.
# It is implemented with the shinydashboard library.
ui <- function(request){
# begin our shinydashboard
shinydashboard::dashboardPage(
#### Header ####
header = shinydashboard::dashboardHeader(
title = shiny::HTML(paste0(strong('Vision Analyze'))),
titleWidth=200 . # make this width match up with sidebar width
),
@shaun-jacks
shaun-jacks / shiny-vision-server-renderUI.R
Last active March 7, 2019 02:25
Portion of server.R that contains dynamic UI with renderUI and uiOutput for R Shiny Google Vision API project
### Body of image_analyze tab ###
output$image_analyze <- renderUI({
### Image upload UI Step ###
if (values$analysis_stage == 1) {
shiny::sidebarLayout(
shiny::sidebarPanel(
title = "Image and Analysis Selection",
# ask for file input from user
shiny::fileInput(
inputId = "file1",
@shaun-jacks
shaun-jacks / shiny-vision-custom.css
Last active March 29, 2023 23:31
R Shiny custom.css style of Shiny Dashboard. Code inspired by user aagarw30 repo
/* header title font */
.main-header .logo {
font-family: "helvetica", serif, Times, "Times New Roman";
font-weight: bold;
font-size: 24px;
}
/* background color of header (logo part) */
.skin-blue .main-header .logo {
background-color: #252525;
@shaun-jacks
shaun-jacks / shiny-vision-reactiveValues-server.R
Last active February 18, 2019 07:45
Initialize Reactive Values to dynamically control ui in R Shiny Vision project
values <- reactiveValues(
analysis_stage = 1, # save stage of ui
file_uploaded = F, # was file uploaded?
analysis_selected = F, # was an analysis type selected?
warning_inputs = "" # initial warning message
)
@shaun-jacks
shaun-jacks / shiny-vision-inputfilepath-save-server.R
Created February 17, 2019 03:27
Save the file-path when user uploads a file
#### When image has been uploaded ####
observeEvent(input$file1, {
values$file_uploaded = T
values$file_path = input$file1$datapath # store uploaded image filepath
})
@shaun-jacks
shaun-jacks / shiny-vision-analyzeBegin-server.R
Last active February 18, 2019 07:48
Observe Event of Action Button to begin RoogleVision to Cloud Vision call from specified image file-path and analysis type
#### When Analyze button toggled ####
observeEvent(input$analyze, {
if (!((values$file_uploaded) & (values$analysis_selected))) {
values$warning_inputs = "Must select an analysis and upload a file"
} else {
# Begin progress bar
shiny::withProgress(message = "Obtaining Google Vision Analysis", value = 0.1, {
shiny::incProgress(amount = 0, detail = "sending photo to Google Vision")
# send to Google Vision
@shaun-jacks
shaun-jacks / shiny-vision-facial-image.R
Last active February 17, 2019 23:03
Code to render facial image using R graphics device and magick library
# We first create an image pointer with image_read(/path/to/image)
photo = magick::image_read(values$file_path)
# obtain photo dimensions
photo_info = magick::image_info(photo)
height = photo_info$height
max_height <- 400 # this variable is used for height parameter within renderImage()
rescale_lwd <- 2/max_height * height # rescale our line widths when drawing
# draw original image without analysis features
magick::image_draw(photo)
@shaun-jacks
shaun-jacks / shiny-vision-datatable-ex-server.R
Created February 18, 2019 00:01
Example of using DT::datatable() to display facial detection results stored within values$img_res
#### Within ui.R or renderUI() ####
DT::dataTableOutput("results")
#### Within server.R ####
output$results <- DT::renderDataTable({
if (values$analysis_type == "FACE_DETECTION") {
as.data.frame(
list(
joy = values$img_res$joyLikelihood,
sorrow = values$img_res$sorrowLikelihood,
@shaun-jacks
shaun-jacks / shiny-vision-server-stage-1-ui.R
Last active March 7, 2019 02:17
UI within renderUI stage 1
## UI STAGE 1 CODE #
# begin a sidebar ui page
shiny::sidebarLayout(
shiny::sidebarPanel(
title = "Image and Analysis Selection",
# ask for file input from user
shiny::fileInput(
inputId = "file1",
label = "Input Image",
accept = c(
@shaun-jacks
shaun-jacks / shiny-vision-server-stage-2-ui.R
Created February 18, 2019 06:41
UI code for stage 2 within renderUI for shiny vision project
# stage 2 within our renderUI function
shiny::fluidPage(
shiny::tagList(
# Row 1: our analyzed image
shiny::fluidRow(
column(8, align = "center",
shinycssloaders::withSpinner( # Spinner loading bar
imageOutput("picture2"), # Outputted Image
color = '#999999'
)