Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
djacob65 committed Jul 22, 2021
1 parent a5dc5ea commit 42c9a99
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 34 deletions.
1 change: 1 addition & 0 deletions dataexplorer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RUN R -e "install.packages(c('JADE'), repos='http://cran.rstudio.com/')" && \
ADD ./ /srv/shiny-server

RUN rm -rf /var/lib/apt/lists/* && \
cp /srv/shiny-server/conf/shiny-server.conf /etc/shiny-server/shiny-server.conf && \
cp /srv/shiny-server/conf/launch-server.sh /usr/local/bin && \
chmod 755 /usr/local/bin/launch-server.sh

Expand Down
7 changes: 5 additions & 2 deletions dataexplorer/Rsrc/Init_UI.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
#----------------------------------------------------
apiKeyModal <- function(failed = FALSE) {
modalDialog(
passwordInput("authkey", "Enter the API Key", width = '400px', placeholder = '' ),
tags$table(tags$tr(
tags$td(passwordInput("authkey", "Enter the API Key", width = '400px', placeholder = '' )),
tags$td(tags$img(id='eyeapikey', src = "eye-close.png", width=30, onclick="javascript:eyetoggle();"))
)),
if (failed)
div(tags$b("Invalid API Key", style = "color: red;")),
footer = tagList(
modalButton("Cancel"), actionButton("okApiKey", "OK")
modalButton("Cancel"), actionButton("okApiKey", "Submit")
)
)
}
Expand Down
23 changes: 11 additions & 12 deletions dataexplorer/Rsrc/libs.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dsname <- ''
dcname <- ''

# ws : Web service connection variables
# 1: API key mode
# 1: API key mode : 0 => no API key, 1 => API key in query string, 2 => API key in HTTP header
# 2: dataset shortname
# 3: API Key
# 4: API URL
Expand Down Expand Up @@ -138,27 +138,26 @@ getAbout <- function () {
# Get 'infos.md' content
getInfos <- function (ws) {
T <- httr_get(ws, paste0('infos/', ws[2]))
if (!is.wsError() && !is.wsNoAuth()) {
if (!is.wsError() && !is.wsNoAuth() && ws[1]>0) {
# Images
P <- na.omit(str_extract(T, pattern="@@IMAGE@@/[^\\.]+\\.(png|jpg)"))
P <- na.omit(str_extract(T, pattern="https?:[^:]+\\.(png|jpg)"))
if (length(P)>0) for (i in 1:length(P)) {
I <- base64_enc(httr_get(ws, paste0('image/', ws[2], '/', gsub('@@IMAGE@@/','',P[i])), mode='raw'))
I <- base64_enc(httr_get(ws, paste0('image/', ws[2], '/', basename(P[i])), mode='raw'))
T <- gsub( P[i], paste0('data:image/png;base64,',I), T )
}
# PDF - markdown link style
P <- na.omit(str_extract(T, pattern="\\[[^\\]]+\\]\\(@@PDF@@/[^\\.]+\\.pdf\\)"))
P <- na.omit(str_extract(T, pattern="\\[[^\\]]+\\]\\(https?:[^:]+\\.pdf\\)"))
if (length(P)>0) for (i in 1:length(P)) {
V <- as.vector(simplify2array(strsplit(gsub('@@PDF@@','',gsub('(\\[|\\]|\\(|\\))','',P[i])),'/')))
urlapi <- paste0(ws[4],'pdf/',ws[2],'/',V[2])
href <- paste0("<a class=\"jlink\" onclick=\"javascript:openPDF('",urlapi,"');\">",V[1],"</a>")
V <- as.vector(simplify2array(strsplit(gsub('(\\[|\\]|\\(|\\))',',',P[i]),',')))
V <- V[ V != "" ]
href <- paste0("<a class=\"jlink\" onclick=\"javascript:openPDF('",V[2],"');\">",V[1],"</a>")
T <- gsub(P[i], href, T, fixed=TRUE)
}
# PDF - normal link style
P <- na.omit(str_extract(T, pattern="@@PDF@@/[^\\.]+\\.pdf"))
P <- na.omit(str_extract(T, pattern="[^']https?:[^:]+\\.pdf"))
if (length(P)>0) for (i in 1:length(P)) {
V <- gsub('@@PDF@@/','',P[1])
urlapi <- paste0(ws[4],'pdf/',ws[2],'/', V)
href <- paste0("<a class=\"jlink\" onclick=\"javascript:openPDF('",urlapi,"');\">",V,"</a>")
urlapi <- substring(P[i],2)
href <- paste0(substring(P[i],1,1), "<a class=\"jlink\" onclick=\"javascript:openPDF('",urlapi,"');\">",basename(urlapi),"</a>")
T <- gsub(P[i], href, T, fixed=TRUE)
}
}
Expand Down
24 changes: 24 additions & 0 deletions dataexplorer/conf/shiny-server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
http_keepalive_timeout 120;

# Define a server that listens on port 3838
server {
listen 3838;

# Define a location at the base URL
location / {
# disable application idle timeouts
app_idle_timeout 0;

# Host the directory of Shiny Apps stored in this directory
site_dir /srv/shiny-server;

# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;

# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;
}
}
2 changes: 1 addition & 1 deletion dataexplorer/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ meta <- tags$head(
'),
tags$script(type="text/javascript", src = "js/google-analytics.js"),
tags$script(type="text/javascript",src = "js/d3.min.js"),
tags$script(type="text/javascript",src = "js/getip.js"),
tags$script(type="text/javascript",src = "js/utils.js"),
tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
)

Expand Down
5 changes: 5 additions & 0 deletions dataexplorer/www/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ p {
display: none;
}

#eyeapikey {
vertical-align: bottom;
cursor: pointer;
}

.jlink {cursor: pointer;}

.dropdown , .dropdown h2 {
Expand Down
Binary file added dataexplorer/www/eye-close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dataexplorer/www/eye-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 35 additions & 19 deletions dataexplorer/www/js/getip.js → dataexplorer/www/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
// Get IP Client
// https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript
// Get a PDF through the API
// apikey, ipclient : global variables
var openPDF = function(url) {
$.ajax({
url: url,
cache: false,
xhrFields: { responseType: 'blob' },
headers: { "x-api-key": apikey, 'x-forwarded-for': ipclient },
success: function(blob) {
var link=document.createElement('a');
link.href=window.URL.createObjectURL(blob);
link.type = 'application/pdf';
link.target='_blank';
link.click();
}
});
}

// Toggle input of the API Key, from 'password' to 'text' and vice-versa
var eyetoggle = function() {
if ( $('#eyeapikey').attr('src') === 'eye-close.png' ) {
$('#eyeapikey').attr('src','eye-open.png');
$('#authkey').get(0).type = 'text';
} else {
$('#eyeapikey').attr('src','eye-close.png');
$('#authkey').get(0).type = 'password';
}
}

// Send IP to Shiny Server
var sendIP = function(theip) {
Shiny.onInputChange("ipclient", theip);
console.log(theip);
}

// Convert data to JSON
var toJSON = function( data ) {
json = data.trim().split('\n').reduce(function(obj, pair) {
pair = pair.split('=');
Expand All @@ -14,6 +42,11 @@ var toJSON = function( data ) {
return json;
}

// Get IP Client
// https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript

// When the shiny session is initialized
// => Get IP Client, then send it to Shiny Server
$( document ).on("shiny:sessioninitialized", function(event) {

$.ajax({
Expand All @@ -40,20 +73,3 @@ $( document ).on("shiny:sessioninitialized", function(event) {

})

// Get a PDF through the API
// apikey, ipclient : global variables
var openPDF = function(url) {
$.ajax({
url: url,
cache: false,
xhrFields: { responseType: 'blob' },
headers: { "x-api-key": apikey, 'x-forwarded-for': ipclient },
success: function(blob) {
var link=document.createElement('a');
link.href=window.URL.createObjectURL(blob);
link.type = 'application/pdf';
link.target='_blank';
link.click();
}
});
}
2 changes: 2 additions & 0 deletions getData/www/inc/infos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ do {
}

$INFOS_TEXT = file_get_contents($ENV['DATADIR']."/$dataset/infos.md");
$INFOS_TEXT = preg_replace('/@@IMAGE@@/', $GETDATA_URL_PROXY."image/$dataset", $INFOS_TEXT);
$INFOS_TEXT = preg_replace('/@@PDF@@/', $GETDATA_URL_PROXY."pdf/$dataset", $INFOS_TEXT);

} while (0);

Expand Down
1 change: 1 addition & 0 deletions getData/www/infos
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ ini_set("include_path", ".:/usr/share/php");
include ('inc/config.inc');
include ('inc/infos.inc');


?>

0 comments on commit 42c9a99

Please sign in to comment.