From a PyScript app, I am providing two radio buttons in my index.html,
allowing a user to decide wether synthesis of isotropic gaussian blobs should be overlapping or not (effectively by toggling the value of Scikit-Learn's cluster_std value for the make_blobs method).
app reference: https://24ec0d6b-0b55-49be-aeb7-a0046c41abf4.pyscriptapps.com/ea775901-75b9-406d-beac-944d26301b09/latest/
I am currently unable to parse the choice into Python booleans (True or False)
and always receive a True value regardless of which radio button that was clicked.
Experimented a bit with defining the values in HTML as double-, single-, or un-quoted as well as switching between different casings (titled, upper, lower) without luck.
Also had a look at other examples/questions here on SO, e.g. How to pass a boolean from javascript to python?
Snippet from the relevant section in the HTML:
<div id="input" style="margin: 20px;">
Should the clusters overlap: <br/>
<input py-click="generate_blobs()" type="radio" id="true" name="overlaps" value="true">
<label for="true"> True</label>
<input py-click="generate_blobs()" type="radio" id="false" name="overlaps" value="false">
<label for="false"> False</label>
</div>
And similarly for the Python snippet:
def generate_blobs():
"""Generate isotropic Gaussian blobs for clustering"""
over_laps = js.document.getElementsByName("overlaps")
for element in over_laps:
if element.checked:
overlap = bool(element.value)
print(overlap, type(overlap))
break
paragraph = Element("Overlap")
paragraph.write(f"overlaps: {overlap}")
n_samples = 4_000 # if overlap else 2_000
cluster_std = 1.5 if overlap else .4
X, y = datasets.make_blobs(
n_samples = n_samples,
n_features = 2,
centers = 5,
cluster_std = cluster_std,
shuffle = True,
)
return X, y
Result from setting the False option:
Any suggestions are most welcome as I am running out of ideas to try
