R/app_gpv2.R

Defines functions app_gpv2

Documented in app_gpv2

#' Shiny Dashboard for GPV curves APP shiny server function
#' @return shiny Dashboard
#' @import shinydashboard
#' @export
#'
app_gpv2 <- function(){

  # UI
  dashboard_ui <-
    shinydashboard::dashboardPage(
      shinydashboard::dashboardHeader(
        title = "RIKO Control Valve"
      ),
      shinydashboard::dashboardSidebar(
        sidebarMenu(
          menuItem("Dashboard",   tabName = "dashboard"),
          menuItem("Op. Table",   tabName = "op_table"),
          menuItem("Kv Value",    tabName = "kv"),  # https://community.rstudio.com/t/shiny-download-ggplot/90532
          menuItem("Zeta Value",  tabName = "zv"),
          menuItem("Sigma Value", tabName = "sigma")
        ),
        shiny::actionButton("go",label = "CALCULATE")
      ),
      shinydashboard::dashboardBody(
        tabItems(
          # First tab content
          tabItem(tabName = "dashboard",
            fluidRow(
              box(title = "Cylinder Type", select_cylinder("cylinder", "VAG")),
              box(title = "Valve Diameter (mm)", select_diameter("diameter")),
              box(title = "Localization above sea level (m)",
                  shiny::sliderInput("masl", label ="", value = 0, min = 0, max = 4000)),
              box(title = "Water Temperature (Celcius)",
                  shiny::sliderInput("temperature", label ="", value = 20, min = 5, max = 30)),
              box(title = "Operation Data",
                  op_data_input_ui("operation_datatable"))
            )
          ),
          tabItem(tabName = "op_table", shiny::tabPanel("Table", DT::DTOutput("table"))),
          tabItem(tabName = "kv",
                  plotOutput("kv_plot"),
                  # https://community.rstudio.com/t/shiny-download-ggplot/90532
                  downloadButton("download_kv_plot", "Download Plot")),
          tabItem(tabName = "zv",    plotOutput("z_plot")),
          tabItem(tabName = "sigma", plotOutput("s_plot"))
        )
      )
    )

  # SERVER
  dashboard_server <- function(input, output, session) {
    ## Initialize a blank data-frame
    v <- shiny::reactiveValues(data = {
      initialize_df(6) # insert the number of observations data
    })

    ## Module for Interact with the input of Operations data
    op_data_input_server("operation_datatable", op_data = v)

    ## Cylinder parameter
    gpv_data <-  shiny::reactive({
      cylinder_parameter("VAG") # insert the Band
    })

    ## Calculation of the Operations point Table
    op_points <- shiny::reactive({
      operation_points(v$data, "VAG", input$cylinder,
                       as.numeric(input$diameter),
                       as.numeric(input$masl),
                       as.numeric(input$temperature))
    })

    output$table <- DT::renderDT({

      ## Require the input button to be non-0
      shiny::req(input$go)

      ## print the Operations point Table
      tab_op_points(op_points())
    })

    ## Render plot Kv Value
    kv_plot <- reactive({
      plot_curves("kv", "VAG", input$cylinder, as.numeric(input$diameter), op_points())
    })

    output$kv_plot <- renderPlot({
      shiny::req(input$go)
      kv_plot()
    })

    output$download_kv_plot <- plot_downloads(kv_plot())


    ## Render plot Zeta Values
    output$z_plot <- renderPlot({
      shiny::req(input$go)
      plot_curves("zv", "VAG",
                  input$cylinder,
                  as.numeric(input$diameter),
                  op_points())
    })

    ## Render plot Sigma Values
    output$s_plot <- renderPlot({
      shiny::req(input$go)
      plot_curves("sigma", "VAG",
                  input$cylinder,
                  as.numeric(input$diameter),
                  op_points())
    })
  }

  # SHINY
  shiny::shinyApp(dashboard_ui, dashboard_server )

}
ratral/gpvapp documentation built on May 13, 2022, 12:51 a.m.