# Connecting RShiny to a running instance of Julia

**URL:** <https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869>\
**Category:** General Usage\
**Created:** [April 19, 2020, 8:33pm UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869 "2020-04-19T20:33:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [April 19, 2020, 8:33pm UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869/1 "2020-04-19T20:33:51Z")

</div>

I have a simulation model in Julia that has the following workflow

```julia
using SimModel
addprocs(SlurmManager(512))  
@everywhere using SimModel
run_simulation(params) # function uses pmap to launch work() over 500 processors

```

Something important to note is that the statement `@everywhere using SimModel` [takes about 7 minutes to run](https://discourse.julialang.org/t/everywhere-takes-a-very-long-time-when-using-a-cluster/35724/5). The actual `run_simulation` is about 20 seconds.

What I would like to do is have a web facing interface for my model. I am mostly experienced with RShiny, so that’s what I am considering but alternatives are welcome.

My idea is to have a user select the parameters using RShiny app, which gets saved as a JSON file, and when user clicks “run”, the julia script executes, reads the JSON file for its parameters, and executes the model. Something like `julia myscript.jl` where `myscript.jl` would run those commands above.

The problem here is obvious, which is that running `julia myscript.jl` will take about 7 minutes to set up the parallel workers as well compile all the functions over and over again.

Ideally what I would like to do have a Julia instance running where I’ve already allocated the nodes (i.e. `addprocs` and the script is basically just “waiting” for input. As soon as user submits their parameters using RShiny, all i have to do is run `run_simulation(params)`.

Any one have an idea on how this can be accomplished?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 19, 2020, 9:03pm UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869/2 "2020-04-19T21:03:42Z")

</div>

You can use PackageCompiler.jl to compile the package before putting it online.

> **[GitHub - JuliaLang/PackageCompiler.jl: Compile your Julia Package](https://github.com/JuliaLang/PackageCompiler.jl)**
>
> Compile your Julia Package. Contribute to JuliaLang/PackageCompiler.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [April 19, 2020, 9:45pm UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869/3 "2020-04-19T21:45:28Z")

</div>

I think the problem still remains that connecting to the workload manager takes about 7-8 minutes, and I don’t think packagecompiler will help with that, but i will try.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 20, 2020, 5:20am UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869/4 "2020-04-20T05:20:03Z")

</div>

Oh I see. I was thinking your issue was compile time, sorry. For that issue, the problem is likely that Julia defaults to an all-to-all topology, but you don’t necessarily need that. Changing the topology can help quite a bit. Doing something like `addprocs(SlurmManager(512),topology=:master_worker)` might give you all of the connections you need, which is exponentially less than all-to-all.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [April 20, 2020, 3:03pm UTC](https://discourse.julialang.org/t/connecting-rshiny-to-a-running-instance-of-julia/37869/5 "2020-04-20T15:03:35Z")

</div>

That’s exactly what I did in my code (see the previous thread), but its still about 7-8 minutes… I will actually try to 1.4 to see if things have improved.
