cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Interactive Notebook with widgets

elgeo
Valued Contributor II

Dear experts,

We need to create a notebook in order the users to insert/update values in a specific table. We have created one using widgets. However the code performed per action selected is visible to the users. Is there a way to have in a the dropdown etc widgets in a notebook available to the users and the code relative to the actions to be in another one where they won't have access?

Thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz_Fatma
Community Manager
Community Manager

Hi @elgeoYou can achieve this by separating the user interface (UI) and the underlying code logic in different notebooks. Let’s break down the steps:

  1. UI Notebook:

    • Create a notebook specifically for the user interface. In this notebook, you’ll design the widgets (such as dropdowns) that users interact with.
    • Use Databricks widgets to create the desired UI elements. These widgets allow users to select options or input values.
    • The UI notebook should be shared with the users, so they can access and interact with the widgets.
  2. Logic Notebook:

    • Create another notebook (let’s call it the “logic notebook”) where you’ll write the code that corresponds to the actions triggered by the UI widgets.
    • In this notebook, handle the logic for inserting or updating values in the specific table.
    • Keep this notebook private or restrict access to only authorized users (such as data engineers or administrators).
  3. Linking UI and Logic:

    • In the UI notebook, use the widgets to capture user inputs (e.g., selected values from dropdowns).
    • When a user interacts with the UI (e.g., selects an option), trigger a command to execute the corresponding logic in the logic notebook.
    • You can use Databricks’ %run magic command to execute code from one notebook in another. For example:
      %run /path/to/logic_notebook
      
  4. Security and Permissions:

    • Ensure that only authorized users have access to the logic notebook. You can control permissions at the notebook level.
    • Users won’t be able to view the code in the logic notebook unless they have explicit access to it.
  5. Error Handling and Validation:

    • Implement error handling and validation in the logic notebook to handle scenarios like incorrect inputs or database errors.
    • Provide informative messages to users in case of issues.

Remember to test thoroughly to ensure that the UI and logic work seamlessly together. By separating the UI and code, you maintain security while allowing users to interact with the widgets effectively. 🚀

For more details on Databricks SQL and how to use it for inserting data, you can refer to the official documentation1.

 

View solution in original post

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @elgeoYou can achieve this by separating the user interface (UI) and the underlying code logic in different notebooks. Let’s break down the steps:

  1. UI Notebook:

    • Create a notebook specifically for the user interface. In this notebook, you’ll design the widgets (such as dropdowns) that users interact with.
    • Use Databricks widgets to create the desired UI elements. These widgets allow users to select options or input values.
    • The UI notebook should be shared with the users, so they can access and interact with the widgets.
  2. Logic Notebook:

    • Create another notebook (let’s call it the “logic notebook”) where you’ll write the code that corresponds to the actions triggered by the UI widgets.
    • In this notebook, handle the logic for inserting or updating values in the specific table.
    • Keep this notebook private or restrict access to only authorized users (such as data engineers or administrators).
  3. Linking UI and Logic:

    • In the UI notebook, use the widgets to capture user inputs (e.g., selected values from dropdowns).
    • When a user interacts with the UI (e.g., selects an option), trigger a command to execute the corresponding logic in the logic notebook.
    • You can use Databricks’ %run magic command to execute code from one notebook in another. For example:
      %run /path/to/logic_notebook
      
  4. Security and Permissions:

    • Ensure that only authorized users have access to the logic notebook. You can control permissions at the notebook level.
    • Users won’t be able to view the code in the logic notebook unless they have explicit access to it.
  5. Error Handling and Validation:

    • Implement error handling and validation in the logic notebook to handle scenarios like incorrect inputs or database errors.
    • Provide informative messages to users in case of issues.

Remember to test thoroughly to ensure that the UI and logic work seamlessly together. By separating the UI and code, you maintain security while allowing users to interact with the widgets effectively. 🚀

For more details on Databricks SQL and how to use it for inserting data, you can refer to the official documentation1.

 
Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!