Skip to content

Instantly share code, notes, and snippets.

@shaun-jacks
Last active March 7, 2019 02:25
Show Gist options
  • Save shaun-jacks/5a41ffaa90c990f997a37b17cf745f3b to your computer and use it in GitHub Desktop.
Save shaun-jacks/5a41ffaa90c990f997a37b17cf745f3b to your computer and use it in GitHub Desktop.
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",
label = "Input Image",
accept = c(
"image/png",
"image/jpeg"
)
),
# provide dropdown menu to select analysis type
shiny::selectInput(
inputId = "analysis_type",
label = "Analysis Type",
choices = c( # key (seen from user): value (for code)
"Select Analysis" = "analysis_select",
"Facial Detection" = "FACE_DETECTION",
"Label Detection" = "LABEL_DETECTION",
"Landmark Detection" = "LANDMARK_DETECTION",
"Logo Detection" = "LOGO_DETECTION",
"Object Localization" = "OBJECT_LOCALIZATION",
"Text Detection" = "TEXT_DETECTION"
)
),
# Allow for user to choose when to analyze with button
shiny::actionButton("analyze", "Analyze!"),
br(),
# If file not uploaded or analysis type not selected, warning
values$warning_inputs
),
shiny::mainPanel(
# do not need anything in here
)
)
### Image Analysis UI Step ###
} else if (values$analysis_stage == 2) {
# 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'
)
)
),
br(),
br(),
# Row 2: our table results
shiny::fluidRow(
column(8, align = "center",
shinydashboard::box(
width=12,
title = "Analysis Results",
solidHeader = TRUE,
DT::dataTableOutput("results"), # Outputted table
collapsible = TRUE,
collapsed = FALSE,
status = "primary"
)
)
),
br(),
br(),
# Row three: our restart button
shiny::fluidRow(
column(8, align = "center",
shiny::actionButton("reset", "Restart")
)
)
)
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment