0

The process_map() function in the server in the R shiny script creates the diagram image as below. My requirement is that there are two attributes "FUN" and "units" that are part of the performance() function. They have standard four values each that are available in the ui code below under PickerInput ID's Case4 and Case5. Currently, I am hard coding the value to create the map, can you help me to use the id's in the server code and make it dynamic such that when I select the value in the PickerInput, the formula fetches the value directly. Thanks and please help.

library(shiny)
library(shinydashboard)
library(bupaR)
library(processmapR)
library(lubridate)
library(dplyr)
library(edeaR)
library(shinyWidgets)
library(DiagrammeR)
ui <- dashboardPage(
dashboardHeader(title = "Diagram Plot",titleWidth = 290),
dashboardSidebar(width = 0),
dashboardBody(
tabsetPanel(type = "tab",
            tabPanel("Overview", value = 1,

                     box(
                       column(1, 
                              dropdown(
                                pickerInput(inputId = "resources", 
                                            label = "", 
                                            choices = c("Throughput Time"), 
                                            choicesOpt = list(icon = c("fa fa-bars", 
                                                                       "fa fa-bars", 
                                                                       "fa fa-safari")), 
                                            options = list(`icon-base` = "")),
                                circle = FALSE, status = "primary", icon = icon("list", lib = "glyphicon"), width = "300px"
                              ),

                              conditionalPanel(
                                condition = "input.resources == 'Throughput Time' ",


                                tags$br(),
                                tags$br(),
                                tags$br(),
                                dropdown(
                                  pickerInput(inputId = "Case4", 
                                              label = "Select the Process Time Summary Unit", 
                                              choices = c("min","max","mean","median"), options = list(`actions-box` = TRUE), 
                                              multiple = F),
                                  circle = FALSE, status = "primary", icon = icon("eye-close", lib = "glyphicon"), width = "300px"
                                ),
                                tags$br(),
                                tags$br(),
                                tags$br(),
                                dropdown(
                                  pickerInput(inputId = "Case5", 
                                              label = "Select the Process Time Unit", 
                                              choices = c("mins","hours","days","weeks"), options = list(`actions-box` = TRUE), 
                                              multiple = F, selected  = "days"),
                                  circle = FALSE, status = "primary", icon = icon("eye-close", lib = "glyphicon"), width = "300px"
                                ))),
                       title = "Process Map", 
                       status = "primary",height = "575", width = "500",
                       solidHeader = T,
                       column(10,grVizOutput("State")),
                       align = "left")


                     ),

            id= "tabselected"
            )))
  server <- function(input, output) { 
  output$State <- renderDiagrammeR(
  {

    if(input$resources == "Throughput Time")
      patients %>% process_map(performance(FUN = mean,units = "days"))
    else
    return()
    })}
  shinyApp(ui, server)

Diagram Image

Adam Shaw
  • 519
  • 9
  • 24

2 Answers2

1

test this:

output$State <- renderDiagrammeR({

      if(input$resources == "Throughput Time")
      {
        if(input$Case4=="mean"){
        patients %>% process_map(performance(FUN = mean,units = input$Case5))}
      else if(input$case4=="min"){
        patients %>% process_map(performance(FUN = min,units = input$Case5))
      }else if(input$case4=="max"){
        patients %>% process_map(performance(FUN = max ,units = input$Case5))
      }else{
        patients %>% process_map(performance(FUN = median ,units = input$Case5))
      }

        }else
        return()
  })

or you can use this:

patients %>% 
process_map(performance(FUN = eval(parse(text=input$Case4)) ,units = input$Case5))

enjoy;)

here is a sample:

library(shiny)

ui <- fluidPage(
selectInput(inputId = "func", label = "Choose The Function", choices = c("mean", "sum", "median"))
,
textOutput("text")
)


server <- function(input, output, session) {
  main_data <- reactive({
    data.frame(a= rnorm(100), b=rnorm(100) )
  })

  output$text <- renderText({
    df <- main_data()

   apply(df,2, FUN =  eval(parse(text=input$func)) )
  })

}
shinyApp(ui = ui, server = server)
Mahdi Baghbanzadeh
  • 540
  • 1
  • 4
  • 10
0

You could use do.call to call a function from its name, see the example below. You can add arguments by adding them in the list in the do.call function, e.g. list(x,units=input$Case5).


enter image description here


library(shiny)

x=c(1,2,3,4,5,6,7)

ui <- fluidPage(
 selectInput('select','Select Function: ', choices=c('mean','max','min','median')),
 textOutput('text')
)

server <- function(input,output)
{
  output$text <- renderText({
    result = do.call(input$select, list(x))
    paste0('The ', input$select, ' of [', paste(x,collapse=', '),'] is ', result)
  })
}

shinyApp(ui,server)

Hope this helps!

Florian
  • 24,425
  • 4
  • 49
  • 80
  • thanks for the help, regarding your "paste0" command, if you can replace it and test this command patients %>% process_map(performance(FUN = result ,units = "days")). Also you need renderDiagrammeR and grvizOutput to call the diagram, I need help here. Thanks. – Adam Shaw Mar 05 '18 at 06:16