Google Colab Form

From GM-RKB
Jump to navigation Jump to search

A Google Colab Form is a Google Colaboratory feature that allows for lightweight UI customization in the Jupyter notebook environment.

  • Context:
    • It can be used to simplify parameter input in running code blocks within the notebook.
    • It can include options such as checkboxes, sliders, and text boxes.
    • It can make the notebook's interactivity and functionality more user-friendly.
  • Example(s):
    • A form to set training parameters in a machine learning notebook.
    • A form to choose a specific dataset from a list for analysis.
  • Counter-Example(s):
    • A regular code cell in a Jupyter notebook without any form UI elements.
  • See: Google Colab, Jupyter Notebook, Data Science.


References

2023

  • Web Chatbot
    • Google Colab Form is a feature provided within Google's web-based platform, Colab, which enables users to create, execute, and share Jupyter notebooks. With the Form feature, users can construct interactive elements such as checkboxes, date fields, and dropdown lists within their notebooks. The addition of forms allows for user input during runtime, enhancing the interactivity of the platform and simplifying the process of data input. Users can use this feature by selecting the 'Add a form' option from the options menu and they can customize the form fields according to their needs. This feature has proven to be a beneficial tool as it simplifies the data input process by providing user-friendly form fields, replacing the traditional method of manually modifying Python variables.

2023

  • (Google Colaboratory, 2023) ⇒ https://colab.research.google.com/notebooks/forms.ipynb Retrieved:2023-10-15.
    • Google Colaboratory (Google Colab) is a free cloud service provided by Google where you can build Jupyter notebooks used mainly for machine learning research.
    • It provides a form feature which can be used to create UI elements for parameter input, making it user-friendly.
# -*- coding: utf-8 -*-
 """Forms

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/notebooks/forms.ipynb

# Forms

Forms provide an easy way to parameterize code. From a code cell, select **Insert → Add form field**.  When you change the value in a form, the corresponding value in the code will change.
"""

# @title String fields

text = 'value' # @param {type:"string"}
dropdown = '1st option' # @param ["1st option", "2nd option", "3rd option"]
text_and_dropdown = 'value' # @param ["1st option", "2nd option", "3rd option"] {allow-input: true}

print(text)
print(dropdown)
print(text_and_dropdown)

# @title Raw fields

raw_input = None # @param {type:"raw"}
raw_dropdown = raw_input # @param [1, "raw_input", "False", "'string'"] {type:"raw"}

print(raw_input)
print(raw_dropdown)

# @title Date fields
date_input = '2018-03-22' # @param {type:"date"}

print(date_input)

# @title Number fields
number_input = 10.0 # @param {type:"number"}
number_slider = 0 # @param {type:"slider", min:-1, max:1, step:0.1}

integer_input = 10 # @param {type:"integer"}
integer_slider = 1 # @param {type:"slider", min:0, max:100, step:1}

print(number_input)
print(number_slider)

print(integer_input)
print(integer_slider)

# @title Boolean fields
boolean_checkbox = True # @param {type:"boolean"}
boolean_dropdown = True # @param ["False", "True"] {type:"raw"}

print(boolean_checkbox)
print(boolean_dropdown)

# @title ## Markdown
# @markdown You can also include Markdown in forms.

# @markdown ---
# @markdown ### Enter a file path:
file_path = "" # @param {type:"string"}
# @markdown ---

"""# Hiding code

You can change the view of the form by selecting **View → Show/hide code** or using the toolbar above the selected code cell. You can see both code and the form, just the form, or just the code.
"""

# @title Click `Show code` in the code cell. { display-mode: "form" }

option1 = 'A' # @param ["A", "B", "C"]
print('You selected', option1)

# @title After running this cell manually, it will auto-run if you change the selected value. { run: "auto" }

option2 = "A" # @param ["A", "B", "C"]
print('You selected', option2)

"""# Using Jupyter Widgets for interactivity

Colaboratory supports the core set of Jupyter Widgets for providing interactions between Python and the browser.

See the official [Jupyter Widgets documentation](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Basics.html).
"""

import ipywidgets as widgets
from IPython.display import display
button = widgets.Button(description="Click Me!")
output = widgets.Output()

def on_button_clicked(b):
  # Display the message within the output widget.
  with output:
    print("Button clicked.")

button.on_click(on_button_clicked)
display(button, output)

"""### Using Jupyter Widgets sliders"""

import ipywidgets as widgets
slider = widgets.IntSlider(value=5, max=10)
display(slider)

# The current value of the slider
slider.value