I'm using the uikit css framework, I want to fixed the navbar on the top?
You need to include 'components/sticky.js' file from UIKit package and add data-uk-sticky directive to your fixed bar div.
For example:
<div data-uk-sticky>...</div>
I suggest to use it with navbar component, for example:
<nav id='top-bar' class="uk-navbar" data-uk-sticky>
...
<ul class="uk-navbar-nav">...</ul>
<div class="uk-navbar-content">...</div>
<div class="uk-navbar-content uk-navbar-center">...</div>
</nav>
Add this to your css file:
.uk-fixed-navigation {
position: fixed;
right: 0;
left: 0;
top: 0;
z-index: 1030;
}
And add uk-fixed-navigtion class to your navbar.
EDIT
You also can use their sticky component
Related
I have several icons that I want to line up at the end of the application. So that when I click on the image, I was transferred to a link. How should I do it?
So far, I have only managed to add this implementation through st.markdown.but they are arranged vertically because I added a new item every time I wrote markdown.
You can create custom components in streamlit using HTML. Maybe you can create a social media component.
Create a file my_component.html
<html>
<head>
<style>
.body {
height: 64px;
}
.parent {
width: 100%;
height: auto;
display: flex;
justify-content: center;
}
.child {
margin: 5px;
height: 32px;
width: 32px;
}
</style>
</head>
<body>
<div class="parent">
<a class = "child" href="https://www.google.com"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1200px-Google_%22G%22_Logo.svg.png" alt="alt" style="width:32px;height:32px;"></a>
<a class = "child" href="https://wwww.reddit.com"><img src="https://www.redditinc.com/assets/images/site/reddit-logo.png" alt="alt" style="width:32px;height:32px;"></a>
<a class = "child" href="https://wwww.facebook.com"><img src="https://facebookbrand.com/wp-content/uploads/2019/04/f_logo_RGB-Hex-Blue_512.png?w=512&h=512" alt="alt" style="width:32px;height:32px;"></a>
</div>
</body>
</html>
I've added 3 links to google, reddit,and facebook respectively. Add or edit these to something custom.
In the streamlit file, you can import HTML files as components using the components library. The implementation I'm sharing is a very simplified version.
import streamlit as st
import streamlit.components.v1 as components
HtmlFile = open("my_component.html", 'r', encoding='utf-8')
source_code = HtmlFile.read()
print(source_code)
st.text("Navbar Component")
components.html(source_code)
It's a bit basic but yields something like this.
I'm trying to convert a string with markdown formatting into an html
text = """
# To be approved
This is a markdown editor, Type here your article body and use the tools or markdown code to style it.
If you need help or you want to know more about markdown, click on the **light bulb** icon in the bottom left of this form.
You can preview your `article ` by clicking on the icons in the bottom right of this form.
**Click here to begin writing**
\```js
var UID = loadUID();
if (UID != false){
var create_article_btn = window.parent.document.getElementById('create_article_btn');
create_article_btn.style.display = 'block';
}
\```
"""
text = pypandoc.convert_text(text,'html',format='md')
text = text.replace('"',"'")
text = text.replace('\n','')
It all works fine except for code blocks and inline codes which are displayed oddly:
the htmlgenerated by pypandoc is:
<h1 id="to-be-approved">
To be approved
</h1>
<p>
<strong>
Please
</strong>
, begin
<em>
your
</em>
article with a title like this:
</p>
<p>
This is a markdown editor, Type here your article body and use the tools or markdown code to style it. If you need help or you want to know more about markdown, click on the
<strong>
light bulb
</strong>
icon in the bottom left of this form. You can preview your
<code>
article
</code>
by clicking on the icons in the bottom right of this form.
</p>
<p>
<strong>
Click here to begin writing
</strong>
</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode js"><code class="sourceCode javascript"><span id="cb1-1">
<span class="kw">var</span> UID <span class="op">=</span> loadUID()
<span class="op">;</span></span><span id="cb1-2"><span
class="cf">if</span> (UID <span class="op">!=</span> <span class="kw">false</span>)
{</span><span id="cb1-3"> <span class="kw">var</span> create_article_btn
<span class="op">=</span> <span class="bu">window</span><span class="op">.
</span><span class="at">parent</span><span class="op">.</span><span class="at">document</span>
<span class="op">.</span><span class="fu">getElementById</span>(<span
class="st">'create_article_btn'</span>)<span class="op">;</span></span>
<span id="cb1-4"> create_article_btn<span class="op">.
</span><span class="at">style</span><span class="op">.</span><span class="at">display
</span> <span class="op">=</span> <span class="st">'block'</span><span class="op">;
</span></span><span id="cb1-5">}</span></code></pre>
</div>
Is there something I'm missing in the pypandoc conversion? How do I stylise the code block with syntax highlight and proper indentation?
Judging by the presence of classes such as source code etc. it seems that there should be a style associated to that.
I got this sorted in a very simple way: I downloaded a css file specific for Pandoc from GitHub: https://gist.github.com/forivall/7d5a304a8c3c809f0ba96884a7cf9d7e
and then since I'm using the srcdoc property of an iframe to populate the html, I'm adding the style link in the srcdoc before the parsed html:
var article_frame = document.getElementById('article_frame');
// add all the styles here (also pandoc.css)
var temp_frame = '<link rel="stylesheet" type="text/css" href="../static/styles/main.css"><link rel="stylesheet" type="text/css" href="../static/styles/read_article.css"><link href="https://fonts.googleapis.com/css?family=Noto+Serif:400,400i,700,700i&display=swap" rel="stylesheet"><link rel="stylesheet" type="text/css" href="../static/styles/pandoc.css">';
temp_frame += //article parsed with pyPandoc...
article_frame.srcdoc = temp_frame;
Also notice that in the css that I linked, the code highlight wasn't working. I figure that removing the >in the lines: 709-737 it works:
code > span.kw { color: #a71d5d; font-weight: normal; } /* Keyword */
code > span.dt { color: inherit; } /* DataType */
code > span.dv { color: #0086b3; } /* DecVal */
...
code span.kw { color: #a71d5d; font-weight: normal; } /* Keyword */
code span.dt { color: inherit; } /* DataType */
code span.dv { color: #0086b3; } /* DecVal */
...
I am trying to set up a small Bokeh app with a DataTable that might contain long text depending on columns. I would like to have a nice tooltip tool to display the full truncated text while moving the mouse above the corresponding cell.
I went through a previous question that might perfectly do the job but I am unable to get the correct result.
Here is the previous question : How to add HoverTool to a Data Table (Bokeh, Python)
The solution I am investigating is the one provided by Ferrard with nice CSS styling.
Unfortunalety I know almost nothing about CSS and html.
Here are the code I am trying to reproduce.
main.py
main.py:
from os.path import dirname, join
import pandas as pd
from bokeh.io import curdoc, show
from bokeh.models import ColumnDataSource, Div
from bokeh.models.widgets import DataTable, TableColumn, HTMLTemplateFormatter
from bokeh.layouts import layout
template = """<div class="tooltip-parent"><div class="tooltipped"><%= value %></div><div class="tooltip-text"><%= value %></div></div>"""
df = pd.DataFrame([
['this is a longer text that needs a tooltip, because otherwise we do not see the whole text', 'this is a short text'],
['this is another loooooooooooooooong text that needs a tooltip', 'not much here'],
], columns=['a', 'b'])
columns = [TableColumn(field=c, title=c, width=20, formatter=HTMLTemplateFormatter(template=template)) for c in ['a', 'b']]
table = DataTable(source=ColumnDataSource(df), columns=columns)
l = layout([[table]])
curdoc().add_root(l)
show(l)
desc.html
<style>
.tooltip-parent {
width: 100%;
}
.tooltipped {
overflow: hidden;
width: 100%;
}
.tooltip-text {
visibility: hidden;
width: 250px;
background-color: rgba(0, 0, 0, 1);
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 5px;
position: relative;
z-index: 1;
top: 100%;
left: 0%;
white-space: initial;
text-align: left;
}
.tooltipped:hover + .tooltip-text {
visibility: visible;
}
div.bk-slick-cell {
overflow: visible !important;
z-index: auto !important;
}
</style>
<h1>Tooltip demo</h1>
This is stupid but I really don't know where I should put the desc.html file in my working dir so the bokeh server can call it... I read through bokeh documentation and pay attention to Directory format for bokeh but did not manage to use either static or templates dir to achieve the proper result.
Here is the final result I am trying to have
https://i.stack.imgur.com/SB815.png (not enough reputation to link an image)
All I have on my side is the DataTable withouth the "Tooltip demo" header and without any tooltip working.
This is my first question on stack, hope everything is fine :)
In a directory style app, you can make a templates/index.html template that has this structure:
{% extends base %}
{% block title %}My Bokeh App{% endblock %}
{% block preamble %}
<style>
/* your styles here */
</style>
{% endblock %}
The app will automatically render itself using this index.html which has your stylesheet included. In general, it would be good for there to be easier ways to add extra stylesheet specifications to Bokeh apps. I'd encourage you to open a GitHub issue to start a discussion.
My background image is not loading though my CSS file. It loads through the front end with:
<img class="top" src={% static "/store/img/store.jpg" %}>
inside of a div but not with: background: url('{{ STATIC_URL }}/store/img/store.jpg'); on the css file.
My path is apps/store/static/store/img/store.jpg, so that's good.
HTML:
<div class="w3-display-container w3-content w3-wide" style="max-width:1600px;min-width:500px" id="home">
<div class="w3-display-bottomleft w3-padding-large w3-opacity">
<h1>SAN MIGUEL'S EXPORTA</h1>
</div>
</div>
CSS:
#home{
/* The image used */
background: url('{{ STATIC_URL }}/store/img/store.jpg') no-repeat;
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-size: cover;
}
If you are using django's standard templating engine you need to load the static files before referencing them. Paste {% load static %} before <img class="top" src={% static "/store/img/store.jpg" %}>
More help with static files here:
https://docs.djangoproject.com/pt-br/2.0/howto/static-files/#configuring-static-files
Feel free to ask more questions to me if you want!
For a project, I'm trying to get an absolute position of an image (to a background image) in an HTML file while the calculation for the position is done in Python.
This is what I passed into Flask with Python:
return render_template('map.html',posx=pos_x, posy=pos_y)
while pos_x and pos_y have values between 0 and 1260 (the height and width of the backround); and this is what i wrote in css and html
.img-container { position: relative; }
.img-container .top {
position: absolute;
top: posx;
left: posy;
z-index: 3
}
</style>
<td>
<div class="img-container">
<img class="top" src="/static/images/map_test1.png" height="70" width="70" alt="">
<img class="bottom" src="/static/images/map_test.png" alt="">
</div>
If you are using flask, a web python framework, you need to put {{}} around your variables you are passing in to your html page.