Shiny app - sending ompr console prints to Shiny app #387
Unanswered
datadrivensupplychain
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Hey Ralph, this should give you a good starting point (if I understood your problem correctly). You can use library(shiny)
library(ompr)
library(ompr.roi)
library(ROI.plugin.glpk)
ui <- bootstrapPage(
numericInput("n", "Number of items", 10),
verbatimTextOutput("text")
)
server <- function(input, output) {
output$text <- renderText({
req(input$n >= 1)
text <- capture.output({
MIPModel() |>
add_variable(x[i], i = 1:input$n, type = "binary") |>
set_objective(sum_over(runif(1) * x[i], i = 1:input$n), "max") |>
add_constraint(sum_over(runif(1) * x[i], i = 1:input$n) <= 2) |>
solve_model(with_ROI("glpk", verbose = TRUE))
})
paste0(text, collapse = "\n")
})
}
shinyApp(ui = ui, server = server) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Thanks Dirk. Yes I want to track the console output live to understand the
solver progress (doesn't really matter if I get the console output after
the solve completes.). I look more into async in a couple weeks when I have
some more time for R&D.
Right now I have my code set up to save the results of solve_model as an
object in the workspace, then I use get_solution to extract the decision
variables into a few different data frames. I then do postprocessing on
those data frames for the Shiny output.
I just did a webinar with RStudio "R in Supply Chain Management" that demos
the app. I'll post a link when the recording is on YouTube.
Ralph Asher
***@***.***
…On Thu, Jan 20, 2022, 2:50 AM Dirk Schumacher ***@***.***> wrote:
Not sure how, but I would look into capture.output and see if it is
possible to live capture the output and append it to a file as soon as it
changes. Then use reactiveFileReader to watch that file. You might need
to start the solver in a background process using callr or shiny's async
model.
—
Reply to this email directly, view it on GitHub
<#387 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASKSE664PUOC6N3QE76MCJDUW7EEDANCNFSM5MLFJ5DQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Maybe this isn't the right forum but SO has failed me. I'm developing Shiny apps that perform supply chain network optimization "under the hood" using ompr and SYMPHONY. I personally like to set the solver to verbose, so I can track solve progress on the console.
Has anyone used ompr with a Shiny app and been able to print the console content to the Shiny app "live"? That would be ideal.
Thanks
Ralph
Beta Was this translation helpful? Give feedback.
All reactions