Is it possible to update a variable in python from JavaScript? - javascript

I have a bokeh server application that displays data in a graph.
I want to be able to get a value from JavaScript and pass it to the bokeh server script and run a function with that new information that will manipulate the graph.
For example;
I have a series of buttons in JavaScript, when the button is pushed, I want to change the data from 'The number of Icecreams sold.' to 'the number of pizzas' by manipulating a variable.
I know that we can achieve this using bokeh's built-in buttons, but I'm really looking for a way for a way to achieve that from an 'on click' from the java side.
From my research, it seems there are plenty of ways to get python to do something to java, but not the other way around.
Is there any advice out there that might set me down the path?

You can define your own Javascript callbacks in the Python code. See the bokeh docs describing this here.

Related

Special process for calculating parameters in Google Data Studio

I want to do a linear regression in Data Studio. I don't know if there is something already existing (I've looked ans it doesn't seem like there is).
What I want is not plotting a linear Regression in a graph but to obtain the Linear regression's coefficients to then make predictions on some user-defined input parameters.
I more or less know how to code the linear regression function in JS. Is there a way to create a field which would take some parameters as an Input and a returns the output JS custom process (involves looping)? I'm not particularly attached to the whole JS process solution if someone has an answer that solves my problem I'm open to it.
You can create a community viz in Data Studio to do this.
Easiest way to do it would be to first assume:
you have a blank HTML page.
your dependent and independent variables are in JS arrays.
you are creating a single page JS application independent of Data Studio.
Starting from there,
write the entire code in JS to calculate the parameters
surface the parameters using JS created DOM elements
use JS to create input elements to take user input of dependent variables
use user input and parameters to make prediction and surface that
So essentially you will end you with a single page JS application. Once this is ready, you can wrap this in the Community Viz framework, link the arrays to the data form Data Studio, and then use the viz in your reports.

How do I fetch a web response to use as a variable in HTML/JavaScript

So I have a tag in my HTML where onclick calls a JavaScript script, and passes a number to it:
<svg id="fillgauge1" onclick="gauge1.update(42);"></svg>
But I also have a web service that streams a number back to me (as text/plain):
http://myserver/stream?GetNumber&token=xyz
What I want is to be able to do is take the result of that service, and pass it to the JavaScript, sort of like this:
<svg id="fillgauge1" onclick="gauge1.update(http://myserver/stream?GetNumber&token=xyz);"></svg>
But, obviously, it isn't as simple as that!
I guess I'm asking a couple of things. Is there a way to retrieve the value like this, within the HTML, or should the operation go into the JavaScript? And if it should go into the JavaScript, what technique or commands do I use? I'm fairly inexperienced (which I'm sure shows) but I can research what to do if I can just get some pointers. My Googling just isn't finding what approach to take, so I'm kind of lost, and any suggestions would be appreciated.
To clarify the scenario, I have an SVG object with a number label on it. The user clicking the object causes the number to update. I can make it update to a fixed value, but I'd like to get that number, live, from a web service. I can easily change that service from serving text/plain to XML or JSON if that's a better technique.

How to implement different languages on html page

I am just a newcomer developing an app with html/css/js via phonegap. I've been searching info on how to make my app be displayed in different languages and Google doesn't understand me.
So the idea is to have a button on index.html that let the user choose the language in which the app will be displayed, in this case Spanish/English, nothing strange like arabic blablabla....
So I guess that the solution must be related to transform all the text that I load in html to variables and then depending on the language selected display the correct one. I have no idea how to make this, and Im not able to find examples. So that's what Im asking for... if someone could give some code snipet to see how html variables works and how should I save user language selection...
Appreciated guys!
This can be done by internationalization (such as i18N). To do this you need separate file for each language and put all your text in it. Search Google for internationalization.
Otherwise you can look into embeding Google Translate.
This depends on the complexity of language-dependencies in the application. If you have just a handful of short texts in a strongly graphic application, you can just store the texts in JavaScript variables or, better, in properties of an object, with one object per language.
But if you expect to encounter deeper language-dependencies as well (e.g., displaying dynamically computed decimal numbers, which should be e.g. 1.5 in English and 1,5 in Spanish), then it’s probably better to use a library like Globalize.js (described in some detail in my book Going Global with JavaScript and Globalize.js). That way you could use a unified approach, writing e.g. a string using Globalize.localize('greeting') and a number using Globalize.format(x, 'n1') and a date using Globalize.format(date, 'MMM d').

Minimizing data sent between client/server in javascript

I am trying to code a multiplayer game demo in javascipt using no libraries. Everything is going pretty good, but in order to get better performance to move forward I am going to have to try minimize the data I sent over my websockets or I won't be able to do much. I have been thinking about the best way to do this. I am using Node.JS + Express + Socket.IO.
At first I was sending the keyboard state of all the keys from each client to the server and quickly narrowed this down to true/false values for only the keys I was using. But now I am thinking that I should really be doing something like assigning decimal literal values (0, 1, 3, 4) to each possible input state that are allowed (possible combinations of inputs) and simply sending that value to the server.
I have more experience in statically typed languages such as C++, Java, etc. so I know how I would do this in those languages. But basically want I want to know is if I have a small number of possible input states. What is the best way to send this data using javascript on both ends. It will be going into a JSON object. Is there anyway for me to send a single byte?
https://gist.github.com/1437195 No idea if this works but that could the most optimized solution. I've never played with byteArray. I have no clue if they play well with socket.io.

Is it possible to write a program to grab the online search result?

Is it possible to write a program to grab the online search result?
Specifically, I want the data from http://portal.uspto.gov/external/portal/pair
sample data are application numbers, for example 9078871,10595401
Yes, they have CAPTCHAs, and I'm willing to type those in by hand. The problem is I have more than 500 application numbers, what shall I do? Are there any easier way for me to do this?
Thanks in advance! Also, the search engine seems to be written in javascript, but I am not exactly sure.
Sure it is possible and why should it not.
I do not know your gap in knowledge that would enable you to archieve this task as you didn't pointed that out.
Step by Step...
Analyze the Website' s code to see how links and content are generated.
Download the source code programaticly
Generate the hyperlinks to your search results
Parse the related data (I have always done this with some ugly regular expressions)
I have digged a little bit in the site you mentioned and what really can be said is that it won't be a 1-hour action as it's writte in Java (JSP; Java Server Pages).
What I so far found out is that you first have to write an equivalent of the function getDossier or use a Webbrowser control that enables you to call javascript manually to get the search results. Then you can simply bake some regular expressions together to parse the data out of the table.

Categories

Resources