Skip to content

Commit

Permalink
clean up shiny gui app
Browse files Browse the repository at this point in the history
  • Loading branch information
gluc committed Jan 9, 2016
1 parent 061979a commit 62084e1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
121 changes: 61 additions & 60 deletions inst/gui/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,63 +118,21 @@ shinyServer(function(input, output, session) {
observeEvent(input$navbar, {
print(paste0("event: navbar ", input$navbar))

# Analysis
if (input$navbar == "analysis") {
tryCatch({
ahpTree <- DoCalculation(input)
#print(GetDataFrame(ahpTree))
decisionMakers <- ahp:::GetDecisionMakers(ahpTree)
if(length(decisionMakers) > 1) {
output$decisionMaker <- renderUI({
radioButtons("decisionMaker",
"Decision Maker: ",
choices = c("Total", decisionMakers),
selected = ifelse(is.null(input$decisionMaker), yes = "Total", no = input$decisionMaker))
})
show(id = "decisionMaker", anim = TRUE)

output$sort <- renderUI({
radioButtons(
inputId = "sort",
label = "Sort: ",
choices = c("Priority", "Total Priority", "Original"),
selected = "Total Priority"
)
})

} else {
output$sort <- renderUI({
radioButtons(
inputId = "sort",
label = "Sort: ",
choices = c("Priority", "Original"),
selected = "Priority"
)
})
#Cannot just remove, because otherwise the value sticks!
updateRadioButtons(session, "decisionMaker", selected = "Total")
hide(id = "decisionMaker", anim = TRUE)
}
#browser()
output$table <- GetTable(input, ahpTree)

},
error = function(e) {
output$table <- renderFormattable(formattable(TRUE, yes = as.character(e)))

})
}

# Visualize
if(input$navbar == "visualizePanel") {
ahpTree <- DoCalculation(input)
#output$visualizeTree <- renderDiagrammeR(GetGraph(ahpTree) )
output$visualizeTree <- renderGrViz(grViz(GetGraph(ahpTree)$dot_code) )
}


if(input$navbar == "AHP File Format") {
#cannot find images
#output$fileFormat <- renderUI(includeMarkdown(rmarkdown::render(system.file("doc", "file-format.Rmd", package="ahp"))))

#does not produce toc
#output$fileFormat <- renderUI(includeMarkdown(system.file("doc", "file-format.Rmd", package="ahp")))

#only works nicely if theme is the same for shiny app and for vignette
output$fileFormat <- renderUI(includeHTML(system.file("doc", "file-format.html", package="ahp")))
}
})
Expand Down Expand Up @@ -223,26 +181,69 @@ shinyServer(function(input, output, session) {

})



# Sort Order
# Calculate AHP
observe({

input$variable
input$decisionMaker
input$ahpmethod
input$sort
ahpTree <- DoCalculation(input)
output$table <- GetTable(input, ahpTree)
#input$ace
input$cutoff
input$level
input$navbar

if (input$navbar == "analysis") {
print("Calculate tree")
tryCatch({
ahpTree <- DoCalculation(input)
#print(GetDataFrame(ahpTree))
decisionMakers <- ahp:::GetDecisionMakers(ahpTree)
if(length(decisionMakers) > 1) {
output$decisionMaker <- renderUI({
radioButtons("decisionMaker",
"Decision Maker: ",
choices = c("Total", decisionMakers),
selected = ifelse(is.null(input$decisionMaker), yes = "Total", no = input$decisionMaker))
})
show(id = "decisionMaker", anim = TRUE)

output$sort <- renderUI({
radioButtons(
inputId = "sort",
label = "Sort: ",
choices = c("Priority", "Total Priority", "Original"),
selected = "Total Priority"
)
})

} else {
output$sort <- renderUI({
radioButtons(
inputId = "sort",
label = "Sort: ",
choices = c("Priority", "Original"),
selected = "Priority"
)
})
#Cannot just remove, because otherwise the value sticks!
updateRadioButtons(session, "decisionMaker", selected = "Total")
hide(id = "decisionMaker", anim = TRUE)
}
#browser()
output$table <- GetTable(input, ahpTree)

},
error = function(e) {
output$table <- renderFormattable(formattable(TRUE, yes = as.character(e)))

})
}
})

# Ahp Method
observeEvent(input$ahpmethod, {
print("event: ahpmethod")

ahpTree <- DoCalculation(input)
output$table <- GetTable(input, ahpTree)
})




## Event Handlers
#############################
Expand Down
2 changes: 2 additions & 0 deletions inst/gui/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ shinyUI(
),
tabPanel(
"AHP File Format",
#done on server because the file format is a vignette
#that is not directly included with the shiny app
uiOutput("fileFormat")
)
),
Expand Down

0 comments on commit 62084e1

Please sign in to comment.