Can't access static_text type from Model subclass?

26 views
Skip to first unread message

Stephen Davies

unread,
Feb 17, 2021, 9:57:24 AM2/17/21
to ProjectMesa
Hello, I'm trying to wire together a simple way to display status updates (in a text box) for the user to give them feedback about long-running simulations.

I thought I could do this using the "static_text" option of UserSettableParameter. But it appears that when I create such a text box, I am prohibited for some reason from passing it as an argument to the model constructor (so that the model could update the text while it's running.)

Minimum (non-)working example:

from mesa import Agent, Model
from mesa.visualization.UserParam import UserSettableParameter
from mesa.visualization.ModularVisualization import ModularServer

class MyModel(Model):
    def __init__(self, in1, msg):
        pass
    def step(self):
        pass
    def run(self):
        pass

if __name__ == "__main__":
    in1 = UserSettableParameter("slider","Input",10,1,100,1)
    msg = UserSettableParameter("static_text", value="<p>Boo</p>")
    server = ModularServer(MyModel, [], "Broken", { "in1":in1, "msg":msg })
    server.port = 8081
    server.launch()


If "msg" is set to any other kind of UserSettableParameter (another slider, for example) this runs without error. As is, I get:

TypeError: __init__() missing 1 required positional argument: 'msg'

Lil help?

Majd Al-shihabi

unread,
Feb 17, 2021, 11:01:27 AM2/17/21
to Stephen Davies, ProjectMesa
Hi Stephen - I suggest that instead of a user-settable parameter, you use a TextElement, or TextData visualization classes. They're more adapted to what you're trying to do, as far as I can tell. Here's an example of how it can be used.

Good luck!

Majd

--
Project repos: github.com/projectmesa
---
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectmesa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectmesa/3cfadea2-66ad-4e7b-afca-68e4ac4872f2n%40googlegroups.com.

Stephen Davies

unread,
Feb 17, 2021, 7:47:03 PM2/17/21
to ProjectMesa
Ah...thanks! I misread the documentation -- I thought those classes were only for ASCII visualizations, not graphical ones.

Works perfect -- thanks much!
Reply all
Reply to author
Forward
0 new messages