Default Value For Radio Input

Hi I created a plot where you can use a select input to filter a dataset by drug name. And I also have a radio input that filters by the time period in which they report last using the drug. I set the default value for the radio input to “12 Month”, but not every drug has the same amount of time periods. So when I select some drugs the plot does not show because the radio input has a null value. Is there a way to programmatically say if the drug does not have a “12 Month” time period just pick whatever time period the drug does have?

For example Alcohol has a 12 Month time period, but a drug like ADHD Either Type only has Lifetime and 30 Day time periods.

Might not be the most elegant solution, but this should work:

viewof radio = {
  const values =, (d) => d.time);
    { key: values.has("12 Months") ? "12 Months" : values.keys().next().value }
1 Like

Awesome! Thank you! This was exactly the type of logic I was looking for.

1 Like