I am trying to replicate some functionalities in Azure Databricks notebooks that I previously used in Jupyter notebooks, specifically related to controlling the visibility of notebook cells and showing JavaScript alerts and executing cells within the notebook. Below are three code snippets that work perfectly in Jupyter but not in Databricks:
Example 1:
from IPython.display import HTML, Javascript, display as IPyDisplay, clear_output
HTML('''
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function code_toggle(){
if (code_shown){
$('div.input').hide('500');
$('#toggleButton').val('Show Code')
}
else {
$('div.input').show('500');
$('#toggleButton').val('Hide Code')
}
code_shown = !code_shown
}
$(document).ready(function(){
code_shown=false;
$('div.input').hide()
});
</script>
<form action="javascript:code_toggle()">
<input type="submit" id="toggleButton" value="Show Code">
</form>
''')
Example 2:
from IPython.display import display, Javascript
display(Javascript("""
alert('Hello, this is a JavaScript alert!');
"""))
Example 3:
display(Javascript('IPython.notebook.execute_cell_range(IPython.notebook.get_selected_index()+1, IPython.notebook.ncells())'))
These snippets help in toggling the visibility of code cells and in displaying JavaScript alerts in Jupyter. However, when I try to implement similar functionalities in Azure Databricks, they do not work because Databricks doesn’t seem to support the same level of integration with JavaScript and HTML that Jupyter does.
Question:
Is there any alternative or method to implement such functionalities in Azure Databricks? Specifically, I am looking for a way to:
Control the visibility of cells in a Databricks notebook.
Execute cells by cell_id withing the same notebook.
Trigger JavaScript alerts or other client-side JavaScript functionalities within the Databricks environment.
Any help or guidance on how to achieve this in Azure Databricks would be greatly appreciated!