Interactive Plot in Agents.jl not clickable

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?

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

fig

my egent_step! function looks like this:

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

I think you should change backend from CairoMakie to GLMakie :slight_smile:

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?

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

1 Like

@Kemper did you manage to solve it?

I tried several things now,

first I was confused because in the documentation:
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

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)

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)

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!

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
´´´