Kubeflow Pipelines How can we create static HTML visualization with embedded iFrame using inline storage? - kubeflow

I am wondering how could I create a simple static HTML visualization for kubeflow pipelines using inline storage?
My use case is I'd like to pass a string with raw html containing a simple iframe.
The sample from the doc does not work for me (kfp sdk v1).
Here is the doc I followed : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#web-app
Thanks

UPDATE:
I tested the Output[HTML] from kfp sdk v2 and it works but I came across other issues.
First of all, Kubeflow html viewer creates an iframe with blank src and srcdoc="your static html". This made it impossible to use an iframe in your html as you'd have a nested iframe (the parent from the html viewer and the nested one from your actual html).
Solution :
I found a solution that works on KFP SDK v1 and v2 for all use cases, I used markdown visualization instead of HTML visualization. Since markdown supports inline HTML, I was able to directly paste my html to the markdown output. Compared to using HTML visualization, this supports iframe.
Here is some code to illustrate the solution :
from kfp.components import create_component_from_func
def markdown_vis(mlpipeline_ui_metadata_path: kfp.components.OutputPath()):
import json
metadata = {
'outputs' : [
{
'storage': 'inline',
'source': f"<iframe src=\"https://www.google.ca/\" frameborder=\"0\" allowFullScreen=\"true\" width=\"950\" height=\"600\"/>",
'type': 'markdown',
}]
}
with open(mlpipeline_ui_metadata_path, 'w') as metadata_file:
json.dump(metadata, metadata_file)
markdown_op = create_component_from_func(markdown_vis)
I also tested the doc and it works :
KFP V1 Doc : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#markdown-1
KFP V2 Doc : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#markdown

Related

To show multiple languages in a single PDF while using jsPDF library

I have a requirement to show multiple languages in a single PDF. We are using jsPDF library.
i tried with different methods
Method 1 :
var doc = new jsPDF()
doc.text(10, 10, 'This is a test')
doc.setLanguage("en-US")
doc.save('english.pdf')
Method 2
doc.addFont("test/reference/MouhitsuBold.ttf", "Mouhitsu", "bold");
doc.setFont("Mouhitsu", "bold");
Both methods are not working for me.
Anyone who developed this scenario in your project please do the help.

How to send a html code as a arguement of function in PDFKIT node modules to genrate its pdf?

when I do .text() then PDFKIT shows this given text in a pdf . The code is given below :-
const doc = new PDFDocument();
// pipe the document to a blob
const stream = doc.pipe(blobStream());
// add your content to the document here, as usual
doc.fontSize(25).text(text, 100, 100);
// get a blob when you're done
doc.end();
But, I want to know the function which can take html code as arguement and render that html code on the pdf . Or suggest any other method but using PDFKIT module only.
pdfkit doesn't interpret HTML natively. There is another module that can parse simple HTML. It may do what you're looking for.
https://www.npmjs.com/package/#shipper/pdfkit-html-simple

Getting paperjs to work in an electron app

Another learning project in the works... I am trying to use paperjs in an electron app.
According to the instructions, I think I should be using paper-jsdom (please correct me if I'm wrong). BTW, I am using TypeScript if that makes a difference. I have an HTML document with nothing but an empty <canvas> and a <script> tag referencing this:
import paper, {Color, Point, Path} from 'paper-jsdom'
window.onload = (): void => {
let canvas = document.getElementById("workspace") as HTMLCanvasElement;
paper.setup(canvas);
let path = new Path();
path.strokeColor = Color.random();
let start = new Point(100, 100);
path.moveTo(start);
path.lineTo(start.add(new Point(200, -50)));
paper.view.update();
};
So right off the bat I get:
Uncaught TypeError: paper_jsdom_1.Path is not a constructor
Ugh... So I tried a few random things (it's late, I'm tired...) and changing my import to:
import paper from 'paper'
import {Color, Point, Path} from 'paper-jsdom'
works, or at least the code above works.
Am I supposed to be importing some things from 'paper' and others from 'paper-jsdom'? What is the correct way to use paperjs in an electron app?
Unfortunately paper-jsdom doesn't seem to have any type info for TS.
Thanks!!
Since you are using Paper.js in the renderer process of Electron, you are using it in the browser context and not in Node.js context so you should use the common paper package which relies on browser Canvas API (and not paper-jsdom which targets browserless usage).
So you should be able to use Paper.js as you would for a website.
From your code example, I see that you are using TypeScript so you can have a look at this simple quickstart project that I made to play with Paper.js and TypeScript.
It uses this kind of import:
import * as paper from 'paper';
And then access Paper.js classes through the imported paper object:
new paper.Path.Circle({
center : paper.view.center,
radius : 50,
fillColor: 'orange',
});
Edit
Here is a repository showing the simplest way of using Paper.js in an Electron app.

"document" in mozilla extension js modules?

I am building Firefox extension, that creates single XMPP chat connection, that can be accessed from all tabs and windows, so I figured, that only way to to this, is to create connection in javascript module and include it on every browser window. Correct me if I am wrong...
EDIT: I am building traditional extension with xul overlays, not using sdk, and talking about those modules: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules
So I copied Strophe.js into js module. Strophe.js uses code like this:
/*_Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
[---]
if (document.implementation.createDocument === undefined) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
and later uses doc.createElement() to create xml(or html?) nodes.
All worked fine, but in module I got error "Error: ReferenceError: document is not defined".
How to get around this?
(Larger piece of exact code: http://pastebin.com/R64gYiKC )
Use the hiddenDOMwindow
Cu.import("resource://gre/modules/Services.jsm");
var doc = Services.appShell.hiddenDOMWindow.document;
It sounds like you might not be correctly attaching your content script to the worker page. Make sure that you're using something like tabs.attach() to attach one or more content scripts to the worker page (see documentation here).
Otherwise you may need to wait for the DOM to load, waiting for the entire page to load
window.onload = function ()
{
Javascript code goes here
}
Should take at least diagnose that issue (even if the above isn't the best method to use in production). But if I had to wager, I'd say that you're not attaching the content script.

Rhino and envjs: share Javascript objects with Java application

I'm using rhino and envjs embedded in my java application as described in the envjs guide
Java code:
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
...
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Global global = Main.getGlobal();
global.init(cx);
Main.processSource(cx, "path/to/your/JSfile");
This is working and my test javascript file correctly loads a remote site and does some manipulation with the HTML elements using jQuery.
What I can't figure out is how to send data from the JavaScript back to my Java application.
Here's my .js file:
load('env.rhino.js');
load('jquery.js');
Envjs.scriptTypes['text/javascript'] = true;
window.location = 'http://[mytestpage].html'
var body = $("body");
print("The body is: "+ $.trim(body));//this prints in the Java console!
//I'd like to call a function in my Java code from the Javascript and pass the bodyText as a parameter to it. How can i do this?
myJavaFunction(bodytext);
So this Rhino tutorial was very useful in learning how to connect your Java to JS.
https://developer.mozilla.org/en-US/docs/Scripting_Java

Resources