R processing on web site - r

I have a current project that consists of 3 parts:
An interface for clients to upload datasets from their equipment.
Process the uploaded datasets using R and some preset coefficients.
Display in a graph with a regression line, allowing the user to click points on the graph to remove them where needed and redraw the regression line automatically (after point removed).
Part 1: This is already done using PHP/Laravel. A simple upload and processing interface.
Part 3: I've been able to set this up in chart.js without any problems.
Part 2 is the sticking point at the moment. What I'd like is to be able to send the data to an rscript and just get the datapoints back so that I can display them. Can anyone give suggestions as to the best way to do this? Is there an api available? Or do I need to install software on the server (not an issue if I do, but I'm hoping to avoid the need to if possible)?
TIA
Carton

There is the package shiny to do everything in R (user side GUI and server side R processing). Since you did it in PHP already, you can either write an R script that is being executed with a shell call from PHP, or build an R REST API with plumber

Related

R - Bibliometrix - Biblioshiny: See R code generated by Biblioshiny

I am using Biblioshiny for Bibliometric analysis. As I am quite new to R, and would like to learn more about the underlaying code used by biblioshiny; I was wondering if it is possible to see the resulting R-code generated through the options configured in the web interface in biblishiny. E.g. when creating a ci-citation network in Biblioshiny, can I see the actual executed R-code used to generate this network?
Recently. I though perhaps one can enable a debug-mode and/or see the code through some logs. I do not know if this is the case, or if better solutions exists.

auto documentation system for R shiny

I ask for any advice how to do documentaion / auto-documentation for larger shiny applications.
R packages have roxygen2, but are there any equivalents of auto-documentation for shiny server and ui code?
I'm working on a developing project of +15k lines of code and we push as much as possible to packages with roxygen2 docs, however all of the observes and reacts in central server script and its subscripts are not auto-documented. I also use git of course.
I have tried to tag every observe, reactive, module etc in source code with a unique ID and draw a diagram manually with corresponding IDs. The diagram describe what type of sub-element and topic. Later I would add all triggers etc. This process is very manual though. Maybe I could use "the reactive log" https://shiny.rstudio.com/articles/debugging.html to autogenerate such documentation?
...update 1: I have tried ShinyTester which reads through source code and try to predict a network of sub-element interactions. It did not handle sourcing of external files, but with a little debug I manage to get the below diagram. Unfortunately, only 5% of elements and interactions were discovered hereby. Maybe ShinyTester could need some contributions. :

Start shiny app with input on shiny-server

My problem is as follows: Think of a shiny-app that handles a text input and presents results for this input. However, I want to limit the possibilities of my customers in a sense, that they can not give the text input manually (due to third-party-API-rate-limits) but only once externally. I retrieve the necessary input in a survey externally and I then want to redirect to my app with the input already given (so that they should not be able to play around with different other inputs).
So basically my question boils down to:
"How can I handle the input to a shiny app through a URL."
Let's say my app runs on
1.1.1.1:3838
which displays my app when I open it in a browser. Could I e.g. transform my app to handle URL-requests such as
1.1.1.1:3838/exampletext
(where 1.1.1.1 represents an IP Address) in a way that it then can process "exampletext" in its calculations and displays already prepared results (without the need of a textInput()-field)
I set up a shiny-server on an AWS EC2 instance but I am struggling to find any recommendations on how to build the infrastructure. I first intended to start a new app for each input in a bash script such as:
./app.R exampletext
and process it in the shiny app then like that:
args <- commandArgs(trailingOnly=TRUE)
textInput <- args[1]
However, I think there should be more clever ways to do this with a shiny app/on a shiny-server (apart from the fact that I don't have a real idea how this could really work out). Should I maybe consider a bash script to help me process the input and automatically start a script? In any case, I would be grateful if someone could at least provide me with some keywords to look for the matter appropriately. Thank you!
EDIT1: As proposed by #jyjek and also in this thread:
How do you pass parameters to a shiny app via URL. I could use an observer object that processes any changes in the URL to other objects. This solved the basic foundations of my problem, however, I could use a more static approach as my main goal is to create a non-changeable input. Therefore it is not necessary for me to adapt to changes in the URL, I rather prefer to give once a URL that should not be changeable.

Use Julia to perform computations on a webpage

I was wondering if it is possible to use Julia to perform computations on a webpage in an automated way.
For example suppose we have a 3x3 html form in which we input some numbers. These form a square matrix A, and we can find its eigenvalues in Julia pretty straightforward. I would like to use Julia to make the computation and then return the results.
In my understanding (which is limited in this direction) I guess the process should be something like:
collect the data entered in the form
send the data to a machine which has Julia installed
run the Julia code with the given data and store the result
send the result back to the webpage and show it.
Do you think something like this is possible? (I've seen some stuff using HttpServer which allows computation with the browser, but I'm not sure this is the right thing to use) If yes, which are the things which I need to look into? Do you have any examples of such implementations of web calculations?
If you are using or can use Node.js, you can use node-julia. It has some limitations, but should work fine for this.
Coincidentally, I was already mostly done with putting together an example that does this. A rough mockup is available here, which uses express to serve the pages and plotly to display results (among other node modules).
Another option would be to write the server itself in Julia using Mux.jl and skip server-side javascript entirely.
Yes, it can be done with HttpServer.jl
It's pretty simple - you make a small script that starts your HttpServer, which now listens to the designated port. Part of configuring the web server is that you define some handlers (functions) that are invoked when certain events take place in your app's life cycle (new request, error, etc).
Here's a very simple official example:
https://github.com/JuliaWeb/HttpServer.jl/blob/master/examples/fibonacci.jl
However, things can get complex fast:
you already need to perform 2 actions:
a. render your HTML page where you take the user input (by default)
b. render the response page as a consequence of receiving a POST request
you'll need to extract the data payload coming through the form. Data sent via GET is easy to reach, data sent via POST not so much.
if you expose this to users you need to setup some failsafe measures to respawn your server script - otherwise it might just crash and exit.
if you open your script to the world you must make sure that it's not vulnerable to attacks - you don't want to empower a hacker to execute random Julia code on your server or access your DB.
So for basic usage on a small case, yes, HttpServer.jl should be enough.
If however you expect a bigger project, you can give Genie a try (https://github.com/essenciary/Genie.jl). It's still work in progress but it handles most of the low level work allowing developers to focus on the specific app logic, rather than on the transport layer (Genie's author here, btw).
If you get stuck there's GitHub issues and a Gitter channel.
Try Escher.jl.
This enables you to build up the web page in Julia.

How to create an interactive script in R to simplify/partly automate the data exploration part?

I would like to make an interactive menu in R - that interacts with me and then performs the selected tasks...I did some googling on interactive R / R user menu / etc. but nothing really helped.
I would like to present myself with the following interactive menu
clear all memory
load data
run regression model
run cluster model
Make a choice please (1,2,3 or 4):
based on the selection it would ask additional input (eg. after option 2, load data it would give all the files present in the data/in directory under my project prepended with a number so I could choose which file to load by simply entering 1,2,3, etc.
I do prepare different datasets to run with my script (for different segments or scenarios) and would like to quickly switch between these. eg. business operational plan Oct'12, consumer budget plan, etc. Also I would not like to reload my data over and over again..
I was thinking of building something 'pseudocode' like
print the menu
ask user for input
ifelse(menuinput==1, source(script1.r),
ifelse(menuinput== 2,source(script2.r),
ifelse(menuinput==3,source(script3.r),NA)))
But I am not sure if there are easier ways to do this.
Thanks,
Geoffrey
If you need to design a customized menu I suggest you take a look Shiny by the folks at Rstudio.
I am using it to create an analysis and data-manipulation GUI for my students. It is a work in progress but should give you an idea of some of the things that are possible. Code and installation instructions linked below:
https://github.com/mostly-harmless/radyant
To see it in action on a server:
http://vnijs.rady.ucsd.edu:3838/marketing/

Resources