Skip to content

Instantly share code, notes, and snippets.

@NehaAkashDeo
Created August 3, 2020 12:20
Show Gist options
  • Save NehaAkashDeo/38548c458603a4765986b9b2ae0e2a23 to your computer and use it in GitHub Desktop.
Save NehaAkashDeo/38548c458603a4765986b9b2ae0e2a23 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML\n",
"\n",
"input_form = \"\"\"\n",
"<div style=\"background-color:gainsboro; border:solid black; width:300px; padding:20px;\">\n",
"Variable Name: <input type=\"text\" id=\"var_name\" value=\"foo\"><br>\n",
"Variable Value: <input type=\"text\" id=\"var_value\" value=\"bar\"><br>\n",
"<button onclick=\"set_value()\">Set Value</button>\n",
"</div>\n",
"\"\"\"\n",
"\n",
"javascript = \"\"\"\n",
"<script type=\"text/Javascript\">\n",
" function set_value(){\n",
" var var_name = document.getElementById('var_name').value;\n",
" var var_value = document.getElementById('var_value').value;\n",
" var command = var_name + \" = '\" + var_value + \"'\";\n",
" console.log(\"Executing Command: \" + command);\n",
" \n",
" var kernel = IPython.notebook.kernel;\n",
" kernel.execute(command);\n",
" }\n",
"</script>\n",
"\"\"\"\n",
"\n",
"HTML(input_form + javascript)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(foo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment