Allow calling ui.add_head_html after page has been sent to the client #2140
Replies: 3 comments 1 reply
-
This is a current limitation of But it might be possible to extend the implementation such that the HTML is sent to the client via websocket. I'll convert the discussion to a feature request. |
Beta Was this translation helpful? Give feedback.
-
Thanks. I am looking forward to the implementation which then makes my code feasible. Well, the follow code is still an abstract of the real one @ui.page('/')
async def exportPDF():
"export PDF from current client's webpage. The filename is friendly username.pdf"
NAME = app.storage.user["username"]
fnPdf = f'{NAME}.pdf'
srcJSGenPDF = r"""
<script type="text/javascript">
function generatePDF() {
... filename: '""" + fnPdf + r"""', // please note we use every client's name to generate JS code
}
</script>
"""
ui.add_head_html(srcJSGenPDF)
ui.button("button can't fire function", color='red').props(''' onclick="generatePDF()" ''') |
Beta Was this translation helpful? Give feedback.
-
I started to implement this feature in PR #2191. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
This is a weird question.
1. the simple and working one
we know that this code will pop up an alert window if we press the red button
2. but this one will not fire
generatePDF
functionIn fact, if I do some inspect I find that browser says
Uncaught ReferenceError: generatePDF is not defined
No, I can't remove
srcGenPDF
andui.add_head_html(srcGenPDF)
out of the functionfn
. Because I will generate new PDF filename for every client according to his username in javascript functiongeneratePDF
, which is calculated in the python functionfn
, as you may guess. Above is just a simplified version of my code. Here is the document on the html and javascript code part in case you need to refer.3. So how to fix this problem by no moving
srcGenPDF
out offn
?Thanks
Beta Was this translation helpful? Give feedback.
All reactions