I'm trying to create a shiny app that will explore the connection between R and Aspen Plus (a chemical process simulator).
I was able to establish this connection successfully using the RDCOMClient package.
Below is an example of this connection:
# Package
library(RDCOMClient)
# COM Object
Aspen <- RDCOMClient::COMCreate("Apwn.Document")
# Path to .bkp simulation file
Path <- "C:/Users/Pedro/Desktop/RAspen/pump.bkp"
# Invoke COM Object
RDCOMClient::.COM(obj = Aspen, name = "InitFromFile2", Path)
Aspen[["Visible"]] <- TRUE
Aspen$visible()
Aspen[["SuppressDialogs"]] <- 1
Aspen$SuppressDialogs()
# Reinitialize Simulation
Aspen$Reinit()
# Run Simulation
Aspen$Run2()
# Calling variable result from simulation
Aspen$Application()$Tree()$FindNode('/Data/Blocks/P1/Input/PRES')$Value()
# Close Aspen Plus
Aspen$Close()
The problem I'm having occurs when trying to create a shiny app with a numeric input that represents a input variable from the simulation. The Aspen$Application()Tree() FindNode("/Data/Blocks/P1/Input/PRES")$Value() code represents the output pressure of a pump and has an initial value of 15 bar.
When I put this expression as the value of a numeric input I get the following error: Error in force (default): attempt to apply non-function. I don't understand why the code works in a regular R script but not in a shiny app
Any idea?
Here is my shiny app:
{# Pacotes -----
library(shiny)
library(RDCOMClient)
}
{# Aspen Plus Connection -----
# COM Object
Aspen <- RDCOMClient::COMCreate("Apwn.Document")
# Path to .bkp simulation file
Path <- "pump.bkp"
# Invoke COM Object
RDCOMClient::.COM(obj = Aspen, name = "InitFromFile2", Path)
}
{# UI -----
ui <- fluidPage(
titlePanel("Aspen Plus Simple Pump Simulation"),
sidebarLayout(
sidebarPanel(
fluidRow(
actionButton(
inputId = "runAspen",
label = "Run",
icon = icon("arrow-alt-circle-right"),
width = "100%"
)
),
br(),
fluidRow(
actionButton(
inputId = "closeAspen",
label = "Fechar Simulação",
icon = icon("times"),
width = "100%"
)
),
br(),
fluidRow(
numericInput(
inputId = "dischargePressureP1",
label = "P1 Discharge Pressure",
# value = 5,
value = (Aspen$Application()$Tree()$FindNode("/Data/Blocks/P1/Input/PRES")$Value()),
min = 1,
max = 100,
step = 1
)
)
),
mainPanel(
)
)
)
}
{# SERVER -----
server <- function(input, output, session) {
observeEvent(input$closeAspen, {
# Close Aspen Plus
Aspen$Close()
})
observeEvent(input$runAspen, {
# Reinitialize Simulation
Aspen$Reinit()
# Run Simulation
Aspen$Run2()
})
}
}
shinyApp(ui = ui, server = server)