This file contains 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
# 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 | |
), |
This file contains 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
### 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", |
This file contains 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
/* 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; |
This file contains 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
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 | |
) |
This file contains 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
#### When image has been uploaded #### | |
observeEvent(input$file1, { | |
values$file_uploaded = T | |
values$file_path = input$file1$datapath # store uploaded image filepath | |
}) | |
This file contains 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
#### 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 |
This file contains 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
# 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) |
This file contains 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
#### 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, |
This file contains 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
## 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( |
This file contains 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
# 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' | |
) |
OlderNewer