Hi @remy,
I use a bokeh server (Python 3.7, bokeh 1.3.4), that generates automatically the page.
(i do not know if
or similar are supported, i will gladly add them later if they are)
(EDIT: I messed it up, but I don’t even know how I activated it in the first places and much less how to fix it, sorry for your eyes)
Here is the source code for the generated page:
<<<
My App
(function() {
var fn = function() {
Bokeh.safely(function() {
(function(root) {
function embed_document(root) {
var docs_json = document.getElementById('1339').textContent;
var render_items = [{"roots":{"1305":"bdcbe8d2-d944-487d-8866-322f9cb61dc7"},"sessionid":"2nZ73ObiRSHSNpllmYGUAv8q4BKyGp8KT3ilATZ0cA4O","use_for_title":true}];
root.Bokeh.embed.embed_items(docs_json, render_items);
}
if (root.Bokeh !== undefined) {
embed_document(root);
} else {
var attempts = 0;
var timer = setInterval(function(root) {
if (root.Bokeh !== undefined) {
embed_document(root);
clearInterval(timer);
}
attempts++;
if (attempts > 100) {
console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");
clearInterval(timer);
}
}, 10, root)
}
})(window);
});
};
if (document.readyState != "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
})();
</script>
>>>
I am not sure it will help, so here is the code in Python:
<<<
from bokeh.models.widgets import Div, Button
from bokeh.layouts import column
from bokeh.models.widgets.input import PasswordInput
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt, InvalidKey
from cryptography.hazmat.backends import default_backend
class Login():
"""Class that adds a simple password protection to the dahsboard"""
def __init__(self, pw_hashed, salt, callback, *cback_args, **cback_kwargs):
"""
pw_hashed: binary string
This is the string that must be entered to access the dahsboard.
salt: binary string
The salt used for the hashing process of the password
callback: function
Function to call if the user enters the right password.
cback_args: any
the arguments for your callback function (e.g. "my_title")
cback_kwargs: any
the named arguments for your callback function (e.g. name='Bob')
"""
self.password = pw_hashed
self.callback = callback
self.cback_args = cback_args
self.cback_kwargs = cback_kwargs
self._backend = default_backend()
self.salt = salt
self.password_text = Div(text="Enter the password then press OK")
# This is were the user inputs the password,
# source code at https://docs.bokeh.org/en/latest/_modules/bokeh/models/widgets/inputs.html
# Docs at https://docs.bokeh.org/en/1.3.4/docs/reference/models/widgets.inputs.html
self.password_field = PasswordInput()
# self.wrong_password_text = Div(text="Wrong password. Try again.")
self.confirm_button = Button(label="OK",
button_type="primary")
self.confirm_button.on_click(self.verify_password)
self.col = column(self.password_text, self.password_field,
self.confirm_button)
def verify_password(self, *e):
self.kdf = Scrypt(salt=self.salt, length=32,
n=2**14, r=8, p=1, backend=self._backend)
try:
self.kdf.verify(str(self.password_field.value).encode(),
self.password)
self.password_text.text = "Success"
self.callback(*self.cback_args, **self.cback_kwargs)
except InvalidKey:
self.password_text.text = "Invalid password"
Hope this helps.
Thank you for your responsiveness remy
P.S.: I reported this because it seemed weird to me and I did not know if it was a bug or a normal behaviour, but in any case it is not a real problem on my side (especially since the “copy to clipboard” function works alright).