OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Changing Taipy selector lov at runtime?

  • Thread starter Thread starter Lucio Carrara
  • Start date Start date
L

Lucio Carrara

Guest
I am trying to change the List of Values of a Taipy selector at runtime, but I keep failing. My lov is defined as the keys of a dictionary in my application, called shapes. I define my selector like this:

Code:
tgb.selector(value="{sel_shape}", lov=list(shapes.keys()), dropdown=True, label="Shapes")

At startup, the default values are loaded correctly. However, I need to be able to change the selector lov when I manipulate the shapes dictionary at runtime. How can I achieve that?

Here's what I tried so far.

Update the shapes dictionary​


Simply updating the dictionary (e.g. adding a new key shapes['new_shape'] = [1, 2, 3]) does not work, as the selector lov does not seem to be a dynamic property.

Define the lov in a state variable​


I redefined the selector as tgb.selector(value="{sel_shape}", lov="{selector_lov}", dropdown=True, label="Shapes") and defined a module global variable selector_lov = shapes.keys(). Then, manipulating the shapes dictionary has no effect on the selector lov.

Reload the page​


Every time I manipulate the dictionary I make sure to reload the local page (navigate(state, to="emitter", force=True)). In my top module I have:

Code:
    def on_navigate(state, page_name, params):        
        if page_name == "emitter":
            state.selector_lov = state.shapes.keys()

Still no change in the selector lov after editing shapes.
<p>I am trying to change the List of Values of a Taipy selector at runtime, but I keep failing. My lov is defined as the keys of a dictionary in my application, called <code>shapes</code>. I define my selector like this:</p>
<pre><code>tgb.selector(value="{sel_shape}", lov=list(shapes.keys()), dropdown=True, label="Shapes")
</code></pre>
<p>At startup, the default values are loaded correctly. However, I need to be able to change the selector lov when I manipulate the <code>shapes</code> dictionary at runtime. How can I achieve that?</p>
<p>Here's what I tried so far.</p>
<h3>Update the <code>shapes</code> dictionary</h3>
<p>Simply updating the dictionary (e.g. adding a new key <code>shapes['new_shape'] = [1, 2, 3]</code>) does not work, as the selector lov does not seem to be a dynamic property.</p>
<h3>Define the lov in a state variable</h3>
<p>I redefined the selector as <code>tgb.selector(value="{sel_shape}", lov="{selector_lov}", dropdown=True, label="Shapes")</code> and defined a module global variable <code>selector_lov = shapes.keys()</code>. Then, manipulating the <code>shapes</code> dictionary has no effect on the selector lov.</p>
<h3>Reload the page</h3>
<p>Every time I manipulate the dictionary I make sure to reload the local page (<code>navigate(state, to="emitter", force=True)</code>). In my top module I have:</p>
<pre><code> def on_navigate(state, page_name, params):
if page_name == "emitter":
state.selector_lov = state.shapes.keys()
</code></pre>
<p>Still no change in the selector lov after editing <code>shapes</code>.</p>
 
Top