Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

Web app - export result as HTML

Solved!
CGB
Level 3
Web app - export result as HTML

Hi,

I recently developped a Web App on Bokeh. On it, I added a button to save the result.

Ideally, I would like save the HTML result in a folder to be able to download it. Unfortunately, on notebook, it works well but not in WebApp : it's like the folder was not found ...

In plan B, I saved the result as a static insight and it works well but I have another problem : I don't know how I can download it.

I take all your suggestion,

Thanks in advance !

0 Kudos
1 Solution
ZachM
Dataiker

Hi @CGB,

It should be possible to write to a managed folder from a webapp. Here's an example Bokeh webapp where I write to a file every time a text input is changed:

import dataiku
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import TextInput

folder = dataiku.Folder("MY_FOLDER")

text = TextInput(title="Text")

# Write the title to a file in the managed folder on update
def update_text(attrname, old, new):
    with folder.get_writer("webapp.txt") as f:
        f.write(text.value.encode())

text.on_change("value", update_text)

inputs = widgetbox(text)
curdoc().add_root(row(inputs))
curdoc().title = "Text"

 

Could you please share the code of the webapp, the error message you're getting, and the code of the notebook where it's working?

Thanks,

Zach

View solution in original post

0 Kudos
4 Replies
ZachM
Dataiker

Hi @CGB,

It should be possible to write to a managed folder from a webapp. Here's an example Bokeh webapp where I write to a file every time a text input is changed:

import dataiku
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import TextInput

folder = dataiku.Folder("MY_FOLDER")

text = TextInput(title="Text")

# Write the title to a file in the managed folder on update
def update_text(attrname, old, new):
    with folder.get_writer("webapp.txt") as f:
        f.write(text.value.encode())

text.on_change("value", update_text)

inputs = widgetbox(text)
curdoc().add_root(row(inputs))
curdoc().title = "Text"

 

Could you please share the code of the webapp, the error message you're getting, and the code of the notebook where it's working?

Thanks,

Zach

0 Kudos
CGB
Level 3
Author

Hi @ZachM,
Thanks a lot for your answer, it helps me to find a perfect solution in my case.
I share the final code used :

import dataiku
from bokeh.resources import CDN
from bokeh.embed import file_html

dataiku.Folder("MY_FOLDER")
my_report = file_html(graph_to_save, CDN, "MY_TITLE")
with open(folder.get_path()+'/MY_FILE.html',"w+") as f:
    f.write(my_report)

 

And just by curiosity, someone knows if its possible to download statit insight ?

 

0 Kudos
ZachM
Dataiker

You can download a static insight by first adding it to a dashboard, and then exporting the dashboard to PDF or to an image.

0 Kudos
CGB
Level 3
Author

Thanks @ZachM