<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can you delete a widget, or force a value to it? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/39746#M27065</link>
    <description>&lt;P&gt;I know this is 5+ years late but I would like to add an answer (or work around) to this in case anyone else was looking for the same solution.&lt;/P&gt;&lt;P&gt;What I did was to essentially 'reset' the widget whenever I had to assign (or force) a value to it.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Cell #1
dbutils.widgets.dropdown("ENVIRONMENT", "DEV", Seq('DEV', 'PROD'))

#Cell #2
dbutils.widgets.removeAll()
# Alternatively
# dbutils.widgets.remove('ENVIRONMENT')

# Cell #3
# ENV = &amp;lt;some logic here&amp;gt;
dbutils.widgets.text('ENVIRONMENT', ENV)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Above seems like cheating and messy to be honest but it works for my use case. I leave the 1st cell as is just in case I needed it for interactive debugging within the notebook. After all, cell #1&amp;nbsp;won't matter once the notebook is plugged into a job/workflow&lt;/P&gt;&lt;P&gt;Honestly, I'm just hoping there is a corresponding &amp;lt;&lt;STRONG&gt;set&lt;/STRONG&gt;&amp;gt; method available for widgets alongside the available &amp;lt;&lt;STRONG&gt;get&lt;/STRONG&gt;&amp;gt; method.&lt;/P&gt;&lt;P&gt;If there's anyone else out there with a better solution as of 2023, I'm all ears!&lt;/P&gt;</description>
    <pubDate>Sun, 13 Aug 2023 14:16:09 GMT</pubDate>
    <dc:creator>Gim</dc:creator>
    <dc:date>2023-08-13T14:16:09Z</dc:date>
    <item>
      <title>Can you delete a widget, or force a value to it?</title>
      <link>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/28799#M20571</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hello everyone!&lt;/P&gt;
&lt;P&gt;Basically, I have a dropdown widget, and at some point I want to change the options available, but still maintain the same selected option.&lt;/P&gt;
&lt;P&gt;The problems that I find are:&lt;/P&gt;
&lt;P&gt;- If I want to delete the widget and create a new one, it seems like the object was not deleted and the "index" of the selected value stayed.&lt;/P&gt;
&lt;P&gt;- the dbutils.widgets.dropdown receive a defaultValue, not the selected value. (is there a function to assign the value?)&lt;/P&gt;
&lt;P&gt;- When I change the list of options with dbutils.widgets.dropdown, I end up viewing (displayed widget), and getting (dbutils.widgets.get()) different values.&lt;/P&gt;
&lt;P&gt;I'm attaching some code that contains said problem.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; , help?&lt;/P&gt;
&lt;P&gt;if not("val" in locals()): &lt;/P&gt;
&lt;P&gt;dbutils.widgets.dropdown("A", "4",["1","2","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt;val=dbutils.widgets.get("A") &lt;/P&gt;
&lt;P&gt;if (val=="5"): &lt;/P&gt;
&lt;P&gt;dbutils.widgets.remove("A") &lt;/P&gt;
&lt;P&gt;dbutils.widgets.dropdown("A", "4",["1","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt;print(dbutils.widgets.get("A")) &lt;/P&gt;
&lt;P&gt;if (val=="3"): &lt;/P&gt;
&lt;P&gt;dbutils.widgets.remove("A") &lt;/P&gt;
&lt;P&gt;dbutils.widgets.dropdown("A", "4",["1","2","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt;print(dbutils.widgets.get("A"))&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0693f000007OoHmAAK"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2515i5EA361EF80C69A93/image-size/large?v=v2&amp;amp;px=999" role="button" title="0693f000007OoHmAAK" alt="0693f000007OoHmAAK" /&gt;&lt;/span&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 14:46:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/28799#M20571</guid>
      <dc:creator>andresfp14</dc:creator>
      <dc:date>2018-04-25T14:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can you delete a widget, or force a value to it?</title>
      <link>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/28800#M20572</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;by the way, this is the code:&lt;/P&gt;
&lt;P&gt;if not("val" in locals()): &lt;/P&gt;
&lt;P&gt;dbutils.widgets.dropdown("A", "4",["1","2","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;val=dbutils.widgets.get("A") &lt;/P&gt;
&lt;P&gt;if (val=="5"): &lt;/P&gt;
&lt;P&gt; dbutils.widgets.remove("A") &lt;/P&gt;
&lt;P&gt; dbutils.widgets.dropdown("A", "4",["1","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt; print(dbutils.widgets.get("A")) &lt;/P&gt;
&lt;P&gt;if (val=="3"): &lt;/P&gt;
&lt;P&gt; dbutils.widgets.remove("A") &lt;/P&gt;
&lt;P&gt; dbutils.widgets.dropdown("A", "4",["1","2","3","4","5","6","7"], "text") &lt;/P&gt;
&lt;P&gt; print(dbutils.widgets.get("A"))&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 14:48:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/28800#M20572</guid>
      <dc:creator>andresfp14</dc:creator>
      <dc:date>2018-04-25T14:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can you delete a widget, or force a value to it?</title>
      <link>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/39746#M27065</link>
      <description>&lt;P&gt;I know this is 5+ years late but I would like to add an answer (or work around) to this in case anyone else was looking for the same solution.&lt;/P&gt;&lt;P&gt;What I did was to essentially 'reset' the widget whenever I had to assign (or force) a value to it.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Cell #1
dbutils.widgets.dropdown("ENVIRONMENT", "DEV", Seq('DEV', 'PROD'))

#Cell #2
dbutils.widgets.removeAll()
# Alternatively
# dbutils.widgets.remove('ENVIRONMENT')

# Cell #3
# ENV = &amp;lt;some logic here&amp;gt;
dbutils.widgets.text('ENVIRONMENT', ENV)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Above seems like cheating and messy to be honest but it works for my use case. I leave the 1st cell as is just in case I needed it for interactive debugging within the notebook. After all, cell #1&amp;nbsp;won't matter once the notebook is plugged into a job/workflow&lt;/P&gt;&lt;P&gt;Honestly, I'm just hoping there is a corresponding &amp;lt;&lt;STRONG&gt;set&lt;/STRONG&gt;&amp;gt; method available for widgets alongside the available &amp;lt;&lt;STRONG&gt;get&lt;/STRONG&gt;&amp;gt; method.&lt;/P&gt;&lt;P&gt;If there's anyone else out there with a better solution as of 2023, I'm all ears!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2023 14:16:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-you-delete-a-widget-or-force-a-value-to-it/m-p/39746#M27065</guid>
      <dc:creator>Gim</dc:creator>
      <dc:date>2023-08-13T14:16:09Z</dc:date>
    </item>
  </channel>
</rss>

