How to change the name of the streamlit app page? - python

I have a web application deployed to Heroku. In the address line of the application, the name of the running file and the designation of the streamlit. How can I change this line with integer. Maybe you need to add some kind of configuration file?
I need to change the line "dashboard . Strealit"
Additionally, I ran into the fact that I have no application theme settings.
How can I enable them?
There is also a question about configuration files. They are located along the path: /.streamlit/
but if I place the code on GitHUB, then where should these files be located, in particular the file config.toml??

A few questions here. To change your page name, you can set that a the beginning of your app code with:
st.set_page_config(
page_title="My Page Title",
)
Streamlit theming was added in a recent update. To update your version and see the theme in the settings, you can run:
pip install streamlit --upgrade
and make sure to save the new version number in your requirements.txt.
Your're right, the config.toml file should be located inside a directory called .streamlit at the root of your app. You would need to commit that directory to your Github repo along with the rest of your files. Other config files, like editor configs, .gitignore, etc should be at the root of your project as well and can be committed with everything else.

Your problem is solved using st.set_page_config().
Streamlit has this attribute to change page title, page icon (favicon),layout, initial sidebar state, sidebar menu items.
Please check the Streamlit documentation answering your query from here,
st.set_page_config.
Use this code at the top of your streamlit_app.py file (if it has your main function)
st.set_page_config(page_title = "New Name")
Regarding the second question,
Use this code in setup.sh file, when ran in the Procfile this will create a dir with the theme configuration set in the config.toml under .streamlit directory.
mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"your-email#domain.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[theme]\n\
base='light'\n\
primaryColor='#3a70ec'\n\
backgroundColor='#FFD600'\n\
secondaryBackgroundColor = '#F0F2F6'\n\
textColor='#0e1862'\n\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
You may also checkout this answer on the second question,
https://stackoverflow.com/a/67001757/12007117
Thanks, upvote if found helpful!😊

You can change the app name, logo, etc. You should write the below code at the beginning of your script.
import streamlit as st
from PIL import Image
image_directory = "C:\\Users\Documents\logo.PNG"
image = Image.open(image_directory)
PAGE_CONFIG = {"page_title":"MyApp",
"page_icon":image,
"layout":"centered",
"initial_sidebar_state":"auto"}
st.set_page_config(**PAGE_CONFIG)

Related

Store credentials for twine upload of artifacts

I'm building my python package using Azure DevOps pipeline and the generated artifact is then uploaded to a feed. Everything is working fine, however, I don't like the fact that I have a .pypirc file containing the credentials for the upload sitting in my repository.
Basically I'm uploading the artifact using:
- script: 'twine upload -r imglib --config-file .pypirc dist/imglib-*.tar.gz'
Is there another way to store the credentials, preferably not in a file that anyone could edit? I read something about storing the credentials in the key vault, but I don't see how change the pipeline (the yml file) to do this.
Thanks in advance.
EDIT:
Shaykis answere seems to be the right way, however, I'm not able to replace the placeholder in the .pypirc file using a bash command. All I get is three asterics when I print the content of .pypirc after replacement. For the replacement I use:
- script: 'sed -i "s/__password__/$PYPI_CRED_MAPPED/g" .pypirc'
displayName: 'Setting PyPI credentials'
env:
PYPI_CRED_MAPPED: $(pypi_cred)
The content of .pypirs is (displayed during the build task using a bash cat .pypirc. Is there an easier way to debug the build prozess?):
[distutils]
Index-servers =
pypi
imglib
[imglib]
Repository = https://pkgs.dev.azure.com/XXX/_packaging/imglib/pypi/upload
username = imglib
password = ***
Does anyone know what is happening there?
EDIT 2:
I also tried to use $env:PYPI_CRED_MAPPED but in that case only the $env is replaced by nothing and all I'm left with is :PYPI_CRED_MAPPED. Also, I look at the docs and they use the variable directly (e.g. $PYPI_CRED_MAPPED, see bottom of page).
EDIT 3:
The three asterics are just a placeholder. It worked with $PYPI_CRED_MAPPED as mentioned in EDIT 2. The build process was failing because of another reason. I also tried it with the powershell command provided in the answer and it worked as well. So thank you for your help.
You can store the variable as a secret variable, in the .pypirc file put a placeholder and in the pipeline add a script that replace the placeholder with the variable.
1) In the .yaml editor click on the 3 dots near the Save/Run button on the top right and then click "Variables".
2) Add a new variable (pythonCred fore example) with the password and click on the lock icon to make it secret.
3) Go to your .pypirc file and replace the password with __password__.
4) In your pipeline add a PowerShell task to put the password:
- powershell: |
(Get-Content path/to/pypirc) -replace "__password__" , "$env:CredPython" | Set-Content -Path path/to/pypirc
env: CredPython: $(pythonCred) # you must to map the variable because is a secret variable
You can also use Azure Key Vault with this way, download the password from there in with Azure Key Vault task and replace update the .pypirc file.

Allure not able to read output.xml file generated by AllureReportLibrary in Robot Framework

I am using Ride (RobotFramework IDE) and I have imported Library AllureReportLibrary in my project.
Using the Set Output Dir, I am creating a Directory C:/AutomationLogs/Allure and all the allure properties and xml files are getting generated in that path.
Set Output Dir C:/AutomationLogs/
Then I am using the "allure serve C:\AutomationLogs\Allure" command to try and generate the html report file in command prompt, but it shows the below error -
"Could not read result
C:\AutomationLogs\Allure\f56f4796-d30a-47f3-a988-d17f6c4e13ca-testsuite.xml:
{} com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot
deserialize va lue of type
ru.yandex.qatools.allure.model.SeverityLevel from String "None":
value not one of declared Enum instance names: [trivial, blocker,
minor, normal, critical]"
The xml file "f56f4796-d30a-47f3-a988-d17f6c4e13ca-testsuite.xml" was generated using the AllureReportLibrary
Also the index.html file which is generated after the command opens after this command and shows Allure Report unknown
unknown - unknown (Unknown) 0 test cases NaN%
I am using the below -
Allure version - 2.4.1
Ride version - RIDE 1.5.2.1 running on Python 2.7.12.
I am new to Robot Framework and Allure. Please let me know whether I have implemented it correctly and why I am facing the above error.
-Ryan M
I'm using the 1.1.1 version of Allure Adaptor for Robot Framework and the severity is picked from the test case tags and added as a label under the test-case element of the report.
However, it seems that Allure 2.6.0 is also expecting a valid value for the severity attribute of the test-case element.
In order to use Allure2 with the current reports I have altered AllureListener.py to also add the severity to the test case:
elif tag in SEVERITIES:
test.severity = tag
test.labels.append(TestLabel(
name='severity',
value=tag
))
If your output.xml has severity = None for any testcase then the allure-robotframework-adaptor will give the error that you have mentioned. Creating TestCase() object with severity='' in start_suitesetup method of AllureListener.py will do the trick.
def start_suitesetup(self, name, attributes):
....
....
test = TestCase(name=name,
description=description,
start=now(),
attachments=[],
labels=[],
parameters=[],
steps=[],
severity='')
How to create the Allure reports in Robot Framework ?
Initially, Download the Command line and UNzip the file and save the path of the bin folder in environment.
Link : http://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.8.0/allure-commandline-2.8.0.zip
Unzip the above file then put it in the Environment folder.
Then Pip install the below modules
pip install allure-robotframework
pip install robotframework-allurereport
In robot file, Add the Library in Settings like,
Example :
Library AllureReportLibrary D:\eclipse\RobotFramework\results
Then Use the Below commands to run the robot code.
robot --listener allure_robotframework;D:\eclipse\RobotFramework\results
Example.txt
Finally,
Generate the HTML file by,
allure generate D:\eclipse\RobotFramework\results
Note : Use the same path what you used in the previous command to generate the HTml.file.
and
Open in Mozhila FireFox. It wont be work in Chrome. I dont know exactly why.
Regards,
Vijay

CNAME file not being copied to root output when publishing Pelican blog

I am following Tip #2 from the Pelican documentation to utilize a custom domain on GitHub pages. For this to work correctly, the CNAME file needs to be at the root of my site.
From the doc:
To use a custom domain with GitHub Pages, you need to put the domain of your site inside a CNAME file at the root of your site. To do this, create the content/extra/ directory and add a CNAME file to it. Then use the STATIC_PATHS setting to tell Pelican to copy this file to your output directory. For example:
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
I have done this. My pelicanconf.py has the following two settings:
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
I have created my CNAME file and placed it in content/extra/CNAME, as described in the documentation.
I publish the application like this:
pelican content --output output --settings pelicanconf.py
This generates my site in the output directory. The pages are all set up correctly. However, CNAME is not at the root. Instead it is at the extra/CNAME location.
I receive no errors or warnings when publishing. If I publish with the --debug parameter, this line appears in the output:
-> Copying H:\mysite\content\extra\CNAME to extra/CNAME
This clearly shows that it's copying it to extra instead of the root. According to the documentation, I've set my STATIC_PATHS and EXTRA_PATH_METADATA correctly to copy this to the root. How do I change my settings so that CNAME is copied to the correct location instead of the extra directory?
maggick was correct in his assessment in the comments.
Could this be a Windows related problem?
There is one tiny mention in the basic settings overview
Extra metadata dictionaries keyed by relative path. Relative paths require correct OS-specific directory separators (i.e. / in UNIX and \ in Windows) unlike some other Pelican file settings. See Path metadata.
(emphasis is mine)
This tidbit of information isn't mentioned in the Path metadata documentation or in the tips, both of which I'd been utilizing.
My solution, since I am running this on Windows, is to change:
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
to:
EXTRA_PATH_METADATA = {'extra\CNAME': {'path': 'CNAME'},}
^ This is OS specific
Notice the single changed slash in the dictionary key.
Strange this behavior. The docs clearly mention that even in windows you need to use forward slashes.
From readthedocs Pelican 3.6.4 - latest release
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
Note: use forward slashes, /, even on Windows.
But this solution works.

Add files to Xcode project through command line ? Use of project.pbxproj file in Xcode?

I was trying to add a plist file to a xcode project through command line, some of the blogs suggested to edit the project.pbxproj file. I searched about the project.pbxproj file but was not able to get much information about it. Can anyone let me know what is use of the project.pbxproj file in xcode? How does one add entries to it?
I am using this repo to work with it.
the script that I wrote is as follows:
import sys
import os
from mod_pbxproj import XcodeProject
def addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name):
print "Cordova project name : " + corodova_proj_name
present_directory = os.getcwd()
path_to_xcode_proj = present_directory + '/' + corodova_proj_name + '/platforms/ios/' + xcode_proj_name + '.xcodeproj/project.pbxproj'
print "Xcode Project Path : " + path_to_xcode_proj
project = XcodeProject.Load(path_to_xcode_proj)
project.get_or_create_group('new group')
project.add_file(plist_file_name)
if __name__ == "__main__":
corodova_proj_name = sys.argv[1]
xcode_proj_name = sys.argv[2]
plist_file_name = sys.argv[3]
print "Xcode Project Name = : " + xcode_proj_name
print "Plist File Path = : " + plist_file_name
addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name)
I will be invoking the script as:
python myscript.py hello HelloWorld manisha-rules_camdo.plist
myscript.py is the script I wrote, hello is the existing cordova project and HelloWorld is the Xcode project created by using cordova platform add iOS.
The command Sequence I will be following will be as follows:
cordova create hello com.example.hello HelloWorld
cordova platform add iOS
py myscript.py hello HelloWorld manisha-rules_camdo.plist
Where hello is the name of cordova project and HelloWorld name of iOS target.
There is a Ruby API from Cocoapods for editing Xcode projects. It also have an active community of developers:
https://github.com/CocoaPods/Xcodeproj
Another great option, especially for Cordova projects, is to use the XCODE node module: node-xcode; you can easily add it via NPM.
Once in place, you can create an after_prepare hook to modify the pbxproj, injecting custom source files, additional frameworks, etc, on every build. In fact, Cordova itself leverages this module during its own build processes.
Within my solution, I first added the module via npm:
npm install xcode --save-dev
And then I created and after_prepare hook to add extra frameworks into my XCode project:
var xcode = require('xcode'),
fs = require('fs'),
rootdir = process.argv[2],
projectPath = rootdir + '/platforms/ios/my-project/project.pbxproj',
proj = new xcode.project(projectPath);
proj.parse(function(err) {
if (err) {
console.log("Oh noes! XCODE project failed to parse:");
console.log(err);
} else {
proj.addFramework('Fabric.framework', {customFramework:true});
proj.addFramework('Crashlytics.framework', {customFramework:true});
proj.addFramework('AdSupport.framework');
proj.addFramework('FacebookSDK.framework', {customFramework:true});
fs.writeFileSync(projectPath, proj.writeSync());
console.log("Updated XCODE project with references to social libs!");
}
});
The XCODE module is smart enough to know if the frameworks / files / etc that you are trying to add are already present, and won't try to add them again.
What you are asking to do is not the most straightforward thing. The Xcode pbxproj file format looks like XML, but I think there's quite a few proprietary / undocumented pieces to it (much like everything iOS). As far as I can tell, Xcode doesn't have any way to add files from the command line.
I did find a Python script that you might be able to use to modify Xcode's project files, but it's a few years old and it might be out of date.
Here is the Blog post that talks about it and here is the current GitHub repo (last updated five months ago, as of the date of me typing this answer).
Give this a try and let me know if it works for you.

Installing a CGI Proxy on Tomcat

I want to setup a proxy for openlayers to use so I followed these steps:
Downloaded the proxy.cgi file from the OpenLayers web site:
http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi
Modify the proxy.cgi file to include my domain in the allowedHosts list:
allowedHosts = ['localhost:6901']
Copy the proxy.cgi file to the following folder:
$TOMCAT_PATH$/webapps/yourApp/WEB-INF/cgi/
Modify the file web.xml of your web app by adding the sections below. You find the file at
$TOMCAT_PATH$/webapps/yourApp/WEB-INF/web.xml
Comment: In case the web.xml file doesn’t exist for your webapp, just create it yourself or copy it from another webapp and modify it. (created!)
Comment: the “param-value” for the “executable” parameter has to contain the path to your Python installation. (it does!)
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>c:\python25\python.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
Modify the file context.xml of your web app by adding the element below. You find the file at $TOMCAT_PATH$/webapps/yourApp/META-INF/context.xml
Restart Tomcat
To use the proxy with OpenLayers, just include this single line into your code:
OpenLayers.ProxyHost = "/yourWebApp/cgi-bin/proxy.cgi?url=";
But when I try to use it like:
/webappname/cgi-bin/proxy.cgi?url=labs.metacarta.com
I get this error:
Some unexpected error occurred. Error text was: list index out of range
I think its related with os.environ["REQUEST_METHOD"] but I dont know how its related ..
You're asking for an environment variable that isn't defined.
You need to either catch and handle the exception or use os.environ.get:
try:
methodq = os.environ["REQUEST_METHOD"]
except KeyError:
methodq = "default value"
Or:
methodq = os.environ.get("REQUEST_METHOD", "default value")
You're submitting :
/webappname/cgi-bin/proxy.cgi?url=labs.metacarta.com
But the proxy.cgi script is trying to do this:
host = url.split("/")[2]
Try http://labs.metacarta.com for your url so proxy.cgi has some slashes to split on, or modify it to parse the url a little smarter.
The answer is: You don't install or use cgi proxy on Tomcat.
cgi is for apache server or IIS that are used as a front-end server. Tomcat may sit behind it. The configuration of Apache is detailed in: http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html
Be warned that OpenLayers warns that its proxy.cgi is only an example and may not have good enough check to stop it from being exploited, i.e. it may run some malicious script.
If you are serving your OpenLayers client page on Tomcat alone and it contains layers from other GeoServer or Mapserver, you can use proxy servlet and specify it as:
OpenLayers.ProxyHost = "sevlet URL on the server that served this page";
http://wiki.apache.org/tomcat/ServletProxy
https://svn.openxdata.org/Experimental/openXmapper/trunk/gwt-openlayers-server/src/main/java/org/gwtopenmaps/openlayers/server/GwtOpenLayersProxyServlet.java
There are reverse proxy or rewrite sevlet solutions to it, too. Please Google on these.

Categories