generated from streamlit/streamlit-hello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_juxtapose.py
63 lines (59 loc) · 1.63 KB
/
streamlit_juxtapose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit.components.v1 as components
def juxtapose(img1: str, img2: str, label1: str, label2: str, height: int = 1000): # data
"""Create a new timeline component.
Parameters
----------
height: int or None
Height of the timeline in px
Returns
-------
static_component: Boolean
Returns a static component with a timeline
"""
# load css + js
cdn_path = "https://cdn.knightlab.com/libs/juxtapose/latest"
css_block = f'<link rel="stylesheet" href="{cdn_path}/css/juxtapose.css">'
js_block = f'<script src="{cdn_path}/js/juxtapose.min.js"></script>'
# write html block
htmlcode = (
css_block
+ """
"""
+ js_block
+ """
<div id="foo" style="width: 95%; height: """
+ str(height)
+ '''px; margin: 1px;"></div>
<script>
slider = new juxtapose.JXSlider('#foo',
[
{
src: "'''
+ img1
+ '''",
label: '{label1}',
},
{
src: "'''
+ img2
+ """",
label: '{label2}',
}
],
{
animate: true,
showLabels: true,
showCredits: true,
startingPosition: "50%",
makeResponsive: true
});
</script>
"""
)
htmlcode = htmlcode.replace('{label1}', label1)
htmlcode = htmlcode.replace('{label2}', label2)
static_component = components.html(
htmlcode,
height=height,
)
return static_component