# Interactive Plot in Agents.jl not clickable

**URL:** <https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747>\
**Category:** General Usage\
**Tags:** plotting, agents, agentsjl\
**Created:** [November 3, 2023, 10:40am UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747 "2023-11-03T10:40:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kemper](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Post date:** [November 3, 2023, 10:40am UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/1 "2023-11-03T10:40:51Z")

</div>

Hi everyone!

I am starting with agent based modelling, but I am not sure if this is a problem with Agents.jl or a general one:

I try to do a very simple interactive plot, and the plot as well as the buttons and slide bars show up, but I can not click them, they are just a statick image.

any ideas?

```julia
fig, p = abmexploration(
    model;
    agent_step!,
    ac=groupcolor, am=groupmarker, as=12
)

fig

```

 ![Plot](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e6c6e1030aaac944a6ffc72a9c9238e0e86b075.png)

my egent\_step! function looks like this:

```julia
function agent_step!(agent, model)
    agent.happy && return #if agent is happy return end
    nearby_same = 0

    for neighbor in nearby_agents(agent, model) # model[2] would give me the agent with the id 2
        if agent.group == neighbor.group
            nearby_same += 1
        end
    end

    if nearby_same >= model.min_to_be_happy
        agent.happy = true
    else
        move_agent_single!(agent, model)
    end
    return
end

```

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [November 3, 2023, 10:42am UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/2 "2023-11-03T10:42:11Z")

</div>

I think you should change backend from `CairoMakie` to `GLMakie` 🙂

---

<div class="post-metadata">

**Author:** ![Kemper](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Post date:** [November 3, 2023, 10:45am UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/3 "2023-11-03T10:45:59Z")

</div>

Thank you for the quick response!  
I am using the GLMakie Package.

`using Agents, InteractiveDynamics, GLMakie`

Or is there some function from CairoMakie in my code?

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [November 3, 2023, 10:47am UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/4 "2023-11-03T10:47:31Z")

</div>

If you are using `Agents.jl >=5.14` you should not import `InteractiveDynamics`, maybe that is messing with something. If that doesn’t work please post you entire code so that we can reproduce the issue to be able to solve it

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [November 3, 2023, 12:03pm UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/5 "2023-11-03T12:03:59Z")

</div>

@Kemper did you manage to solve it?

---

<div class="post-metadata">

**Author:** ![Kemper](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Post date:** [November 3, 2023, 12:41pm UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/6 "2023-11-03T12:41:09Z")

</div>

I tried several things now,

first I was confused because in the documentation:  
[https://juliadynamics.github.io/InteractiveDynamics.jl/dev/agents/](https://juliadynamics.github.io/InteractiveDynamics.jl/dev/agents/)

the Plotting functions like `abmexploration ` are `InteractiveDynamics` functions.

But in the other Documentation:  
[https://juliadynamics.github.io/Agents.jl/stable/examples/agents\_visualizations/#Agents.abmexploration](https://juliadynamics.github.io/Agents.jl/stable/examples/agents_visualizations/#Agents.abmexploration)

The same functions, like `abmexploration` or `abmplot` are `Agents.jl` functions.

But when I execute the code above without having `InteractiveDynamics`  
loaded, it does not know the functions.

So I thought it might be some version issue, in the documentation they use ` Agents v5.17.1` and I use `Agents v5.14.0`, but because of some conflicting versions I can not update it right now (still fighting)

---

<div class="post-metadata">

**Author:** ![Kemper](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Post date:** [November 3, 2023, 1:18pm UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/7 "2023-11-03T13:18:16Z")

</div>

Okay, before you dig in to deep, I just found another post with the same problem!  
I could not reproduce his solution yet, but I will give it a try first!

[Agents.jl abm\_data\_exploration function returns static image - New to Julia - Julia Programming Language (julialang.org)](https://discourse.julialang.org/t/agents-jl-abm-data-exploration-function-returns-static-image/62936)

---

<div class="post-metadata">

**Author:** ![Kemper](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@Kemper](https://discourse.julialang.org/u/Kemper)\
**Post date:** [November 3, 2023, 2:14pm UTC](https://discourse.julialang.org/t/interactive-plot-in-agents-jl-not-clickable/105747/8 "2023-11-03T14:14:50Z")

</div>

Now I got it running, I cant exactly say how.  
Probems involved where defenitly:

1. I tried to run it in a notebook
2. Later I run it in vs code, where there where issues with `Agents` and ` InteractiveDynamics` -if both are loaded the use must be quallified!
3. fore some reason it worked when I run it in the REPL that opens when I start Julia from the Start menu in Windows, but not in vs studio first. After some time, restarting, reloading, and playing around it also worked in vs studio - fore some reason…

This is the working code:

Thanks for the Help!

```julia
using Agents, GLMakie, InteractiveDynamics

space = GridSpace((10,10))

mutable struct Schelling <: AbstractAgent
    id::Int
    pos::Tuple{Int, Int}
    group::Int
    happy::Bool
end

properties = Dict(:min_to_be_happy => 3)
scheduler = Schedulers.randomly 

model = AgentBasedModel(Schelling, space; properties, scheduler)

function initialize(; N = 320, M = 20, min_to_be_happy = 3 ) #N= number of agents, m= grid coordinates along each dimention
    space = GridSpace((M,M))
    scheduler = Schedulers.randomly 
    properties = Dict(:min_to_be_happy => min_to_be_happy)
    model = AgentBasedModel(Schelling, space; properties, scheduler)

    # adding Agents
    for n in 1:N
        agent = Schelling(n, (1,1), n < N/2 ? 1 : 2, false)
        add_agent_single!(agent, model)
    end
    return model
end

function agent_step!(agent, model)
    agent.happy && return #if agent is happy return end
    nearby_same = 0

    for neighbor in nearby_agents(agent, model) # model[2] would give me the agent with the id 2
        if agent.group == neighbor.group
            nearby_same += 1
        end
    end

    if nearby_same >= model.min_to_be_happy
        agent.happy = true
    else
        move_agent_single!(agent, model)
    end
    return
end

groupcolor(agent) = agent.group == 1 ? :blue : :orange
groupmarker(agent) = agent.group == 1 ? :circle : :rect

model = initialize()

fig, p = abmexploration(
    model;
    agent_step!,
    ac=groupcolor, am=groupmarker, as=12
)

fig
´´´
```
