I have an Rscript that uses RSelenium to web scraping. I included this script as a function in my shinyApp. When I run it from my machine (locally) everything works as expected. The trouble occurs when it is published on the shiny server. When I call the application, it shows the message "Dissconected from the sever".
My shinyApp code:
library(shiny)
library(RSelenium)
ui <- fluiPage(
actionButton('go', 'Scrape')
)
server <- function(input, output, session){
observeEvent(input$go, {
NEW_PATH = paste(Sys.getenv("PATH"), "/usr/lib/jvm/jdk-17/bin/", sep = ":"
Sys.setenv(PATH)
rs_driver <- rsDriver(browser = 'chrome',
chromever = '91.0.4472.101',
port = 4587L,
verbose = T,
check = F)
obj <- rs_driver$client
obj$navigate("http://10.18.33.9:7007/ui/")
Sys.sleep(1)
})
}
shinyApp(ui, server)
How can I get this to work on the shiny server? Please help! Thank you so much
Related
Maximo 7.6.1.1:
I want to run a Maximo automation script by invoking a URL in a separate system.
Is it possible to do this?
This is a great use-case and something that we've been working through in the last few days.
Create automation script. - mine is called automation_api_test
Manually invoke it through the API using a browser to make sure that you can actually get it to run. (%servername%/maximo/oslc/script/automation_api_test?var1=1212321232&var2=1555&site=OPS&_lid=wilson&_lpwd=wilson)
Script it like you would your regular automation script. Here's one that can read in a few parameters from the URL and use those to perform operations in the core system.
importPackage(Packages.psdi.server);
importPackage(Packages.psdi.util.logging);
var resp = {};
// Get the Site ID from the Query Parameters
//var site = request.getQueryParam("site");
var var1 = request.getQueryParam("var1");
var var2 = request.getQueryParam("var2");
var site = request.getQueryParam("site");
//var zxqponum = request.getQueryParam("ponum");
//logger.debug(zxqprinter);
service.log("TESTING script Params" + request.getQueryParams());
service.log("var1 " + request.getQueryParam("var1"));
service.log("var2 " + request.getQueryParam("var2"));
//count the number of WO's in the site
var woset = MXServer.getMXServer().getMboSet("WORKORDER", request.getUserInfo());
woset.setQbe("SITEID","="+site);
var woCount = woset.count();
resp.wo_count = woCount;
woset.close();
// Get Total Count
resp.total = woCount;
//create the response - still not sure why I had to append the vars to a string.
resp.var1= "" + var1;
resp.var2= "" + var2;
resp.site= "" + site;
var responseBody = JSON.stringify(resp);
Here's an expanded version of Kasey's answer.
Create a sample automation script in Maximo:
Automation Scripts >> More Actions >> Create >> Script
Script [name]: HELLOWORLD
Script Language: js
Paste in this code:
//THIS IS JAVASCRIPT! NOT JYTHON!
//load("nashorn:mozilla_compat.js"); //More info about this here: https://stackoverflow.com/questions/57537142/maximo-js-automation-script-importpackage-is-not-defined
//importPackage(Packages.psdi.server);
//importPackage(Packages.psdi.util.logging);
var resp = {};
var var1 = request.getQueryParam("var1");
resp.var1= " " + var1 + " World!";
var responseBody = JSON.stringify(resp);
Click Create
Try out a URL:
This URL will send the word "Hello" to the automation script. The automation script will append the word " World!" onto "Hello".
The phrase, "Hello World!" is returned.
In a browser, run this URL: http://yourhostname:1234/maximo/oslc/script/helloworld?var1=Hello&_lid=wilson&_lpwd=wilson
Replace yourhostname with your host name
Replace 1234 with your port number
Replace maximo with the appropriate value.
The URL request should return this JSON object to the browser:
{"var1":" Hello World!"}
From there, create a hyperlink in a separate system (using the above URL). And click it to run the automation script.
If the last line in the script were to be deleted, nothing would be returned to the browser.
Note:
The URL only seems to work for me under the WILSON user. It doesn't work with my own user:
{"oslc:Error":{"oslc:statusCode":"401","spi:reasonCode":"BMXAA7901E","oslc:message":
"You cannot log in at this time. Contact the system administrator.","oslc:extendedError"
:{"oslc:moreInfo":{"rdf:resource":"http:\/\/something\/maximo\/oslc\
/error\/messages\/BMXAA7901E"}}}}
Best guess is: my user is not set up correctly.
Here's a really simple JavaScript example:
responseBody = "asdf";
Then just run the URL in a browser (or somewhere else like an automation script in Maximo or a Python script in GIS).
https://<<my host>>/maximo/oslc/script/testscript
It's pretty much the same for Python (no semi-colon):
responseBody = "asdf"
I'm programming a shiny app for image analysis using R and EBImage package. The shiny app run locally successfully. After some trials, I want to access to app via shinyapps.io platform.
In shinyapps.io, the app renders images (static) display correctly, but not the interactive one. It remains blank.
¿Some idea?
Thanks
This is the code:
library("shiny")
library("EBImage")
ui <- fluidPage(
# Application title
titlePanel("Image display"),
# Sidebar with a select input for the image
sidebarLayout(
sidebarPanel(
fileInput("image", "Select image")
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Static raster", plotOutput("raster")),
tabPanel("Interactive browser", displayOutput("widget"))
)
)
)
)
server <- function(input, output) {
img <- reactive({
f <- input$image
if (is.null(f))
return(NULL)
readImage(f$datapath)
})
output$widget <- renderDisplay({
req(img())
display(img())
})
output$raster <- renderPlot({
req(img())
plot(img(), all=FALSE)
})
}
# Run the application
shinyApp(ui = ui, server = server)
I stumbled upon this problem as well. I think that caused by fact that the display function is designed to be used from interactive sessions.
The fix consists simply in adding the method parameter to the display call. So your code should be:
...
output$widget <- renderDisplay({
req(img())
display(img(), method = 'browser') # <- this should make the trick
})
...
For testing purpose, I used Xvfb.
Today, I want to do some test with wmctrl commmand. I do some test in python like this :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()
In this test, wmctrl says :
Cannot get client list properties.
(_NET_CLIENT_LIST or _WIN_CLIENT_LIST)
I think, it's normal because I haven't any window manager attach to my Xvfb.
How to start a windows manager (Enlighenment should be good for my case) to manage only Xvfb ?
After some days of works, I can answer myself. Solution is easy as possible : just start windows manager with variable DISPLAY set. So in my python script, I just do :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
# start windows manager
pWM = subprocess.Popen( ["/usr/bin/enlightenment_start", ] )
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()
I was trying to log in using LibCurl. Actually I am using LuaCurl the binding of libCurl in Lua. I am referring to this web page: http://www.hackthissite.org/articles/read/1078
I tried this:
> require("libcurl")
> c=curl.new()
> c:setopt(curl.OPT_USERAGENT,"Mozilla/4.0")
> c:setopt(curl.OPT_AUTOREFERER,true)
> c:setopt(curl.OPT_FOLLOWLOCATION,true)
> c:setopt(curl.OPT_COOKIEFILE,"")
> c:setopt(curl.OPT_URL,"https://www.chase.com")
> res=c:perform()
But after this last operation the program is stuck as if waiting for something. What am I doing wrong here?
Thanks
I tried your program and it seems to work fine. What I get is the content of the given site pumped to stdout. It seems you are just having networking issues...
If you want to capture the whole output as a string and process it later, you have to provide a callback using OPT_WRITEFUNCTION which will be called with more data which you can save. Here is a simplified version of how I implemented the GET method in my simple web-mining toolbox WDM.
local c = curl.new()
...
function get(url)
c:setopt(curl.OPT_URL,url)
local t = {} -- output will be stored here
c:setopt(curl.OPT_WRITEFUNCTION, function (a, b)
local s
-- luacurl and Lua-cURL friendly way
if type(a) == "string" then s = a else s = b end
table.insert(t, s) -- store this piece of data
return #s
end)
assert(c:perform())
return table.concat(t) -- return the whole content
end
I'm trying to map a drive using WNetAddCOnnection2 but there's something not quite right. The code that I am using from pinvoke.net and seems to work at first. If I am stepping through the code I get a 0 for a response and I am able to use System.IO.Directory.GetFiles() to inspect the new mapped drive which leads me to believe that credentials are fine.
The problem is that the drive is not available outside of the application. When I type net use from a command prompt I see the drive listed like this:
Unavailable L: \\<server>\<share> Microsoft Windows Network
When I try to access the drive I get either:
The system cannot find the drive specified.
or
The system cannot find the path specified.
Any help would be greatly appreciated.
Here's the nutshell of the code in question:
NETRESOURCE res = new NETRESOURCE();
res.iScope = RESOURCE_GLOBALNET;
res.iType = RESOURCETYPE_DISK;
res.iDisplayType = RESOURCEDISPLAYTYPE_SHARE;
res.iUsage = RESOURCEUSAGE_CONNECTABLE;
res.sRemoteName = share;
res.sLocalName = drive;
res.sProvider = null;
int iFlags = 0;
iFlags = CONNECT_UPDATE_PROFILE;
int iResult = WNetAddConnection2( ref res, psPassword, psUsername, iFlags );
The iResult always ends up equaling 0.
MSDN articles that may assist:
* WNetAddConnection2 - [http://msdn.microsoft.com/en-us/library/aa385413%28VS.85%29.aspx][1]
* NETRESOURCE - [http://msdn.microsoft.com/en-us/library/aa385353%28VS.85%29.aspx][2]
I reckon your problem is the display type where "res.iDisplayType = RESOURCEDISPLAYTYPE_SHARE". Perhaps try changing to a value of "0" (RESOURCEDISPLAYTYPE_GENERIC). So for example, what I generally use to map drives appears:
With Res
.dwScope = RES_SCOPE_GLOBALNET 'value 2
.dwType = RES_TYPE_DISK 'value of 1
.dwUsage = RES_USE_CONNECT 'value of 1
.localName = "x:" 'leave blank for no drive
.RemoteName = "\\\"
End With
lRes = WNetAddConnection2(Res, sPassword, sDomain & "\" & sPassword, RES_CNN_UPDATE_PROFILE)
If lRes = 0 Then
'Success
Else
'Error
End If
Always check your connections before & after calls from command prompt:
1a) From system making connection, list current connections:
net use
1b) From system connected too, list current sessions:
net session
To disconnect session, use API 'WNetCancelConnection2', my code following from above:
sServer = "\\\"
lRes = WNetCancelConnection2(sServer, RES_CNN_UPDATE_PROFILE, True)
If lRes `> 0 Then
'Success
Else
'Error
End If
Alternatively, simply making connections using 'net' command:
1) To map a drive letter:
net use `: \\`\` /user:`\` `
2) To map an IPC connection:
net use \\`\` /user:`\` `
Disconnecting using 'net' command:
1) Disconnecting mapped drive:
net use `: /delete
2) Disconnecting server share:
net use \\`\` /delete