05-25-2022 12:31 PM
Trying to use displayHTML from w/in a Python module gets a Python exception:
NameError: name 'displayHTML' is not defined
and I've found no way around this. It seems to be something at the UI layer or something, not a Python function that can be referenced/imported or accessed/used from w/in code. Other notebooks provide methods for rendering HTML from w/in Python modules running in the notebook. The Ipython display/HTML methods don't work. Is there a Python function that will render HTML?
Here are a couple external issue I found:
https://stackoverflow.com/questions/71474139/how-to-import-displayhtml-in-databricks
https://github.com/sassoftware/saspy/issues/462
Any insight would be appreciated.
Thanks,
Tom
10-31-2023 10:51 AM
Looks like this works!
from IPython.display import HTML, display
from IPython import get_ipython
try:
shell = get_ipython().__class__.__name__
if shell == 'DatabricksShell':
display(HTML(html_string))
kudos to this stackoverflow answer: https://stackoverflow.com/questions/71474139/how-to-import-displayhtml-in-databricks
05-27-2022 09:20 AM
@Tom Weber please check if the below docs help you
https://docs.databricks.com/notebooks/visualizations/html-d3-and-svg.html
https://docs.microsoft.com/en-us/azure/databricks//notebooks/visualizations/#--displayhtml-function
05-27-2022 09:44 AM
Hey, thanks for reaching out. Unfortunately no, those don't help at all. I know the displayHTML call is the way a user renders HTML themselves by typing it into a cell. The problem is that that function doesn't exist in Python such that it can be executed by imported modules running in that environment.
I support a module users use which can provide results that are returned as HTML and, in other notebooks, rendered using the appropriate function for those environments, from my code; the user doesn't have to get the HTML object and manually render it themselves. That doesn't work in this notebook.
Trying to call that from w/in a module results in a NameError exception and I can find no way to get this function available in my module:
NameError: name 'displayHTML' is not defined
Sorry, I didn't put all the info in here; the links to the issues had all that so I didn't dump it all in here.
But again, I appreciate you replying. Have any ideas about using it from w/in an imported module?
Thanks!
Tom
06-13-2022 11:09 AM
So is there really no way for Python code executing in a notebook (in a cell) to render HTML? It can only be done by an end user typing in displayHTML() themselves in a cell (passing in a string of HTML)? Other notebooks (Jupyter, Zeppelin) have functions for rendering HTML too, but code can call it (and it renders), or users can invoke it themselves too. Is there any way for executing Python code to render HTML in databricks?
Thanks,
Tom
06-16-2022 04:36 AM
06-16-2022 08:09 AM
I'm guessing that's just the same as typing it into a cell in a python notebook in the first place? Which obviously works. Executing it from inside a Python module is what doesn't work. Hope this picture comes through, and again, thanks for responding and trying to help. Hope this makes it more clear.
05-02-2023 01:42 PM
So, still trying to get an answer on how code executing on behalf of what a user typed into a cell (they called a method from my package) can render HTML. Is there really no way for this to work in databricks? This works in Jupyter and Zeppelin, though they each have their own methods that have to be used (but they exist and I use them) Does databricks have no way for code to render HTML for a cell?
Thanks again,
Tom
10-31-2023 10:24 AM
I am facing exactly the same issue. Any progress?
10-31-2023 10:46 AM
Hey @ptweir , I'm afraid I've not even gotten anyone to reply who understands the problem. Looking back, looks like I opened this a year and a half ago. I'm not sure if databricks developers monitor this; it seems to be a users helping users forum. We have one of those too, but I try to keep up with it since most of our users aren't really github types. So, I try to help on any channel they may use. I can't find anything that goes directly to databricks folks. So, no, I've gotten nothing on this. Sorry you're stuck on this too. 😞
10-31-2023 10:51 AM
Looks like this works!
from IPython.display import HTML, display
from IPython import get_ipython
try:
shell = get_ipython().__class__.__name__
if shell == 'DatabricksShell':
display(HTML(html_string))
kudos to this stackoverflow answer: https://stackoverflow.com/questions/71474139/how-to-import-displayhtml-in-databricks
10-31-2023 11:03 AM
Interesting, that's just the Jupyter way to render HTML, which is my default. That didn't work back then, else I'd have never had an issue to start with! So, maybe they've realized the problem and fixed it silently? Well, I'm going to try to connect and test this out, but I'm still skeptical. But that's just my nature :). I'll post back after I can give this a try! If it's finally fixed, then that's great! I'll let you know ...
10-31-2023 10:57 AM
I'm using it in a python package here and just tested that it works in databricks.
10-31-2023 11:23 AM
Holy Guacamole Batman! It works finally!!!! Wow, thanks @ptweir That's awesome! I can go back and update my doc (and code, to just use databricks the same, now, and Jupyter!) and it'll work by default. It's great they fixed it, shame they never told us. But I'll take the fix!
Thanks again for reaching out on this, that's great!
Thanks,
Tom
10-31-2023 12:30 PM
Yay!!
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group