Simmer and Shiny?

309 views
Skip to first unread message

Victor Hugo Nassau Batista

unread,
Jan 26, 2018, 2:29:57 AM1/26/18
to simmer-devel
Hello,

I just saw this possibility to build web apps with the Shiny package from R studio and I was thinking about applying it with the simulation from Simmer, to make it more user friendly. Have you ever seen some application of this type? Or maybe integration with Excel?

Thanks,

Iñaki Úcar

unread,
Jan 26, 2018, 8:23:14 AM1/26/18
to simmer-devel
2018-01-26 8:29 GMT+01:00 Victor Hugo Nassau Batista
<victor.hu...@gmail.com>:
> Hello,
>
> I just saw this possibility to build web apps with the Shiny package from R
> studio and I was thinking about applying it with the simulation from Simmer,
> to make it more user friendly. Have you ever seen some application of this

Some months ago, Shawn Garbett shared with us some of the work (see
[1]) they are developing at Vanderbilt. It's a very nice example of
the possibilities of exposing simmer simulations using Shiny.

> type? Or maybe integration with Excel?

Why would anyone want to do that... :D :D

Iñaki

[1] https://statcomp2.vanderbilt.edu/RIGHT/

Victor Hugo Nassau Batista

unread,
Jan 26, 2018, 9:28:24 AM1/26/18
to simmer-devel
Thanks Inaki!

Well, it might sound stupid, but I don't know how to do this integration with excel. Some example code would help a lot.

I just found the github for the RIGHT project that you mentioned and I'm checking. I'll contact the author! Thank you!

Iñaki Úcar

unread,
Jan 26, 2018, 9:40:19 AM1/26/18
to simmer-devel
2018-01-26 15:28 GMT+01:00 Victor Hugo Nassau Batista
<victor.hu...@gmail.com>:
> Thanks Inaki!
>
> Well, it might sound stupid, but I don't know how to do this integration
> with excel. Some example code would help a lot.

I was joking. I mean, I don't know how to do that, but I don't want to
know either. From my point of view, the only interesting integration
is the one that allows to extract information from Excel sheets to R,
thus freeing you from the Excel chains. :)

Iñaki

Shawn Garbett

unread,
Jan 26, 2018, 11:46:20 AM1/26/18
to simmer...@googlegroups.com
It is theoretically possible to construct a web server in Excel. I have actually investigated this in my curious evil hacks pile, but haven't found the time to do so. Other ideas on the backburner, a git repository that contains itself (finding that hash collision is really hard it's like hunting bitcoin) and I actually need my CPU for productive work. Net requests that spawn 2 net requests should always point at each other. Finding Godel incomplete flaws in corporate rules and filing the paperwork requests for it to be delivered is a moral imperative. Evil geniuses for a better tomorrow is a great organization.

As far as the RIGHT code, our paper is coming out soon and I'll ask the PI if the code can be shared. It does contain the code that generated our main results, but in a crippled form (i.e., limited number of trajectories). If you contact me directly, I might be able to forward you the code. I had it up on github earlier but took it down due to embargo on the paper methods till publication.


--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel+unsubscribe@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq1_rsj6Zne%2B%2BEF4ki1WNRd94J4A_DsGyPUNpry9ADXsxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Shawn Garbett
615.397.8737

Iñaki Úcar

unread,
Jan 26, 2018, 11:59:12 AM1/26/18
to simmer-devel
2018-01-26 17:46 GMT+01:00 Shawn Garbett <shawn....@gmail.com>:
> It is theoretically possible to construct a web server in Excel.

I heard that Microsoft plans to add Python to Excel. That would be an
interesting movement.

> I have
> actually investigated this in my curious evil hacks pile, but haven't found
> the time to do so. Other ideas on the backburner, a git repository that
> contains itself (finding that hash collision is really hard it's like
> hunting bitcoin) and I actually need my CPU for productive work. Net
> requests that spawn 2 net requests should always point at each other.
> Finding Godel incomplete flaws in corporate rules and filing the paperwork
> requests for it to be delivered is a moral imperative. Evil geniuses for a
> better tomorrow is a great organization.

Search "zip that contains itself" on Google and you'll get some fun. ;-)

> As far as the RIGHT code, our paper is coming out soon and I'll ask the PI
> if the code can be shared. It does contain the code that generated our main
> results, but in a crippled form (i.e., limited number of trajectories). If
> you contact me directly, I might be able to forward you the code. I had it
> up on github earlier but took it down due to embargo on the paper methods
> till publication.

BTW, we have a paper about simmer in the Journal of Statistical
Software. It's accepted and in their publication queue, although
there's no volume and DOI yet. Still, it would be great if you could
cite it as "accepted for publication".

Iñaki

Victor Hugo Nassau Batista

unread,
Jan 29, 2018, 7:06:35 AM1/29/18
to simmer-devel
Hello,

I checked the code on github and made some improvement on building the interface. My simulation is much more simpler than the one in the RIGHT project. I'm just interested in changing a few parameters and showing some plots.

My problem is to call the simmer simulation from the server in Shiny. As I understood, I must create a function with the run() statement for simmer and call it from the server. The problem is that I'm running my simulation based on a data.frame containing the starting times of the arrivals, and it is returning an error.
> simulation <- function()
+ {
+   env<-simmer("Transportation")
+   env %>% add_generator("packstück", Production_Line, at(df$TIME_START_min))
+   env %>% run(until=max(df$TIME_START_min))
+ }
> simulation()
Error in run_(private$sim_obj, until) : Branch: index out of range
Called from: run_(private$sim_obj, until)
Or any better idea on how to call the simulation?

Thanks,

Iñaki Úcar

unread,
Jan 29, 2018, 7:30:55 AM1/29/18
to simmer-devel
2018-01-29 13:06 GMT+01:00 Victor Hugo Nassau Batista
<victor.hu...@gmail.com>:
> Hello,
>
> I checked the code on github and made some improvement on building the
> interface. My simulation is much more simpler than the one in the RIGHT
> project. I'm just interested in changing a few parameters and showing some
> plots.
>
> My problem is to call the simmer simulation from the server in Shiny. As I
> understood, I must create a function with the run() statement for simmer and
> call it from the server. The problem is that I'm running my simulation based
> on a data.frame containing the starting times of the arrivals, and it is
> returning an error.
>
>> simulation <- function()
> + {
> + env<-simmer("Transportation")
> + env %>% add_generator("packstück", Production_Line,
> at(df$TIME_START_min))
> + env %>% run(until=max(df$TIME_START_min))
> + }
>> simulation()
> Error in run_(private$sim_obj, until) : Branch: index out of range
> Called from: run_(private$sim_obj, until)

The last part of the error is always the meaningful part: "Branch:
index out of range". Check your branches. There is one of them whose
option parameter is returning a value that is probably higher than the
number of sub-trajectories defined.

Iñaki

Victor Hugo Nassau Batista

unread,
Feb 2, 2018, 11:05:09 AM2/2/18
to simmer-devel
Is it possible to show a very simple app with the bank tutorial?
library(simmer)
library(shiny)

set.seed(1234)

bank <- simmer()

customer <-
  trajectory("Customer's path") %>%
  log_("Here I am") %>%
  set_attribute("start_time", function() {now(bank)}) %>%
  seize("counter") %>%
  log_(function() {paste("Waited: ", now(bank) - get_attribute(bank, "start_time"))}) %>%
  timeout(input) %>%
  release("counter") %>%
  log_(function() {paste("Finished: ", now(bank))})

bank <-
  simmer("bank") %>%
  add_resource("counter") %>%
  add_generator("Customer", customer, function() {c(0, rexp(4, 1/10), -1)})

# User interface ----
ui <- fluidPage(
  titlePanel("simple example"),

  sidebarLayout(
    sidebarPanel(
      h3("Buttons"),
      numericInput("input", "input timeout", 15),
      actionButton("simulate","Simulate", icon(" fa-arrow-circle-o-right"))
    ),
    mainPanel(
      plotOutput("plot")
    )
  )
)

# Server logic
server <- function(input, output) {
  ### HERE ## HOW CAN I CALL THE INPUT TO BE USED ON THE SIMULATION?
  bank %>% run(until = 400)

  output$plot <- renderPlot({
    plot(env, "resources", "usage","counter",item=c("server","queue"),steps=T)
  })
}

# Run the app
shinyApp(ui, server)


I just don't know how to transform the simulation script into a function in a way that it will interact with the app, that is, the plots and all the information I want will be visible to the app... :'(

Iñaki Úcar

unread,
Feb 2, 2018, 11:19:48 AM2/2/18
to simmer-devel
2018-02-02 17:05 GMT+01:00 Victor Hugo Nassau Batista
<victor.hu...@gmail.com>:
> Is it possible to show a very simple app with the bank tutorial?
>
> library(simmer)

library(simmer.plot)
There is some useful info here:
http://shiny.rstudio.com/articles/action-buttons.html

>
> output$plot <- renderPlot({
> plot(env, "resources",
> "usage","counter",item=c("server","queue"),steps=T)

Plot bank, not env.

> })
> }
>
> # Run the app
> shinyApp(ui, server)
>
>
>
> I just don't know how to transform the simulation script into a function in
> a way that it will interact with the app, that is, the plots and all the
> information I want will be visible to the app... :'(
>
>
>

Iñaki

Victor Hugo Nassau Batista

unread,
Feb 2, 2018, 12:33:00 PM2/2/18
to simmer-devel
Hello,

Shawn Garbett just shared with me the changes he made to make it work. I did very few changes, but it works very good.

library(shiny)
library(simmer)

ui<-fluidPage(

  # Application title
  titlePanel("Simple App"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("customers",
                  "Number of customers:",
                  min = 1,
                  max = 50,
                  value = 30),
      actionButton("execute", "Run Model")
    ),

    # Show a plot of the generated distribution
    mainPanel(
      textOutput("serviceTime"),
      textOutput("numCustomers")
    )
  )
)

# simmer model as function of input
bankModel <- function(input)
{
  customer <- trajectory("Customer's path") %>%
    log_("Here I am") %>%
    timeout(10) %>%
    log_("I must leave")

  bank <- simmer("bank") %>%
    add_generator("Customer", customer, at(1:input$customers)) %>%
    run() %>%
    wrap()

  bank
}

# This forces shiny to see a usage of inputs in simmer model
# Not always needed, but enough to be troublesome without
copyInputs <- function(inputs)
{
  list(
    customers = inputs$customers
  )
}

# Define server logic required to draw a histogram
server <-function(input, output) {

  observeEvent(input$execute, {
    model   <- bankModel(copyInputs(input))
    output$serviceTime  <- renderText(as.character(model$now()))
    output$numCustomers <- renderText(as.character(input$customers))
  })

}

# Run the app
shinyApp(ui, server)


Thank you very much!

Iñaki Úcar

unread,
Feb 2, 2018, 1:18:40 PM2/2/18
to simmer-devel
2018-02-02 18:32 GMT+01:00 Victor Hugo Nassau Batista
<victor.hu...@gmail.com>:
> Hello,
>
> Shawn Garbett just shared with me the changes he made to make it work. I did
> very few changes, but it works very good.

Great! Thanks, for sharing it!

Iñaki

ROHIT KALRA

unread,
May 18, 2020, 10:22:55 AM5/18/20
to simmer-devel
Hello Victor,

Thanks for sharing the code. I tried running this, but I am getting following error message. Would you have info on how to fix this?

Warning: Error in renderText: attempt to apply non-function
  [No stack trace available]

Iñaki Ucar

unread,
May 18, 2020, 10:32:53 AM5/18/20
to simmer-devel
On Mon, 18 May 2020 at 16:23, ROHIT KALRA <rkalr...@gmail.com> wrote:
>
> Hello Victor,
>
> Thanks for sharing the code. I tried running this, but I am getting following error message. Would you have info on how to fix this?
>
> Warning: Error in renderText: attempt to apply non-function
> [No stack trace available]

Hi Rohit,

The snippet below is using an old private API. To make it work, just
substitute "model$now()" with "now(model)".

Regards,
Iñaki
> --
> You received this message because you are subscribed to the Google Groups "simmer-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/c6b43d98-89ca-4186-becb-c9ff107e004c%40googlegroups.com.



--
Iñaki Úcar

ROHIT KALRA

unread,
May 18, 2020, 10:45:18 AM5/18/20
to simmer-devel
Hi Iñaki ,

Much thanks! That worked.



Regards,
> To unsubscribe from this group and stop receiving emails from it, send an email to simmer...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages