Skip to content

Commit 0ba3b50

Browse files
committed
allow autofit to work in streamlit
1 parent ba8694d commit 0ba3b50

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

mols2grid/molgrid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ def to_pages(self, subset=None, tooltip=None, n_cols=5, n_rows=3,
581581

582582
template = env.get_template('pages.html')
583583
template_kwargs = dict(
584+
padding = 18,
584585
width = width,
585586
height = self.img_size[1],
586587
border = border,
@@ -819,6 +820,7 @@ def to_table(self, subset=None, tooltip=None, n_cols=5,
819820

820821
template = env.get_template('table.html')
821822
template_kwargs = dict(
823+
padding = 18,
822824
border = border,
823825
textalign = textalign,
824826
cell_width = cell_width,
@@ -846,7 +848,7 @@ def display(self, width="100%", height=None, iframe_allow="clipboard-write",
846848
"""
847849
doc = self.render(**kwargs)
848850
iframe = (env.get_template("html/iframe.html")
849-
.render(width=width, height=height, padding=18,
851+
.render(width=width, height=height,
850852
allow=iframe_allow, doc=escape(doc)))
851853
return HTML(iframe)
852854

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
function fit_height(obj) {
3+
obj.style.height = 0;
4+
var height = obj.contentDocument.body.scrollHeight + {{ padding }} + 'px';
5+
obj.style.height = height;
6+
}
7+
</script>
8+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
9+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>

mols2grid/templates/html/iframe.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<script>
2-
function fit_height(obj) {
3-
obj.style.height = 0;
4-
var height = obj.contentDocument.body.scrollHeight + {{ padding }} + 'px';
5-
obj.style.height = height;
6-
}
7-
</script>
81
<iframe class="mols2grid-iframe" frameborder="0" width="{{ width }}"
92
{% if height %}
103
height="{{ height }}"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/2.3.1/list.min.js"></script>
2-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
32
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
4-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
3+
{% include 'html/common_header.html' %}
54
<script src="https://unpkg.com/@rdkit/rdkit@2022.3.1/Code/MinimalLib/dist/RDKit_minimal.js"></script>

mols2grid/templates/js/pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ window
107107
listObj.update();
108108
// resize iframe to fit content
109109
if (window.frameElement) {
110-
window.parent.fit_height(window.frameElement);
110+
fit_height(window.frameElement);
111111
}
112112
});

mols2grid/templates/table.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
/* custom CSS */
77
{{ custom_css }}
88
</style>
9-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
109
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
11-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
10+
{% include 'html/common_header.html' %}
1211
<!-- custom header -->
1312
{{ custom_header }}
1413
</head>
@@ -29,7 +28,7 @@
2928
})
3029
// resize iframe to fit content
3130
if (window.frameElement) {
32-
window.parent.fit_height(window.frameElement);
31+
fit_height(window.frameElement);
3332
}
3433
</script>
3534
{% endif %}

0 commit comments

Comments
 (0)