run app from terminal error with rstudioapi::selectDirectory - shiny

I want to launch a shiny application from a terminal. My application has a button that when pressed opens a window to select a folder with the function rstudioapi::selectDirectory()
But when i click on the button i get this error:
Warning: Error in : RStudio not running
76: stop
75: verifyAvailable
74: callFun
73: rstudioapi::selectDirectory
72: observeEventHandler [D:/Users/folder/Shiny/app.R#12]
1: shiny::runApp
app.R
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
actionButton("folder", "Choose folder")
)
server <- function(input, output) {
observeEvent(input$folder, {
path.file <- rstudioapi::selectDirectory()
print(path.file)
})
}
# Run the application
shinyApp(ui = ui, server = server)
on a terminal
$ "Rscript.exe" -e "shiny::runApp('Shiny/app.R')"
Loading required package: shiny
Warning: package 'shiny' was built under R version 3.5.3
Listening on http://127.0.0.1:6283
Warning: Error in : RStudio not running
76: stop
75: verifyAvailable
74: callFun
73: rstudioapi::selectDirectory
72: observeEventHandler [D:/Users/folder/Shiny/app.R#12]
1: shiny::runApp

You are running in a Shiny process, not RStudio.

Related

Run a app from terminal and send a password

I want to launch a shiny application from a terminal to avoid blocking the rstudio console.
My application uses the ssh package to connect to a remote machine.
When I launch the application from rstudio a small window opens to ask me for my password but when I launch the application from the terminal i get an error message.
$ "Rscript.exe" -e "shiny::runApp('app')"
Loading required package: shiny
Warning: package 'shiny' was built under R version 3.5.3
Warning: package 'ssh' was built under R version 3.5.3
Linking to libssh v0.8.6
Password callback did not return a string value
Erreur : Authentication with ssh server failed
Stopped
app.R
library(shiny)
library(ssh)
ssh.session <- ssh::ssh_connect(host = host)
cat("*** Logging in of the session ***")
# Define UI for application that draws a histogram
ui <- fluidPage()
server <- function(input, output) {
onStop(function() {
ssh_disconnect(ssh.session)
cat("*** Logging out of the session ***")
})
}
# Run the application
shinyApp(ui = ui, server = server)
I don't know about your security necessity in your use case...
What you could'd do (if its ok for you to specify a password while calling Rscript), is giving the password as an extra parameter when calling RScript and then forwarding it to ssh_connect(). You could also do the same with host variable. Im calling this R file via:
Rscript --vanilla home/user/R/app.R "password"
I'm not running shiny::runApp, because the line shinyApp(ui=ui, server=server) will automatically start up the shiny application, allowing us to connect to ssh beforehand.
In the app.R file we forward the arguments to ssh_connect.
app.R
library(shiny)
library(ssh)
args <- commandArgs(trailingOnly = TRUE)
host="host"
ssh.session <- ssh::ssh_connect(host = host,passwd = )
cat("*** Logging in of the session ***")
# Define UI for application that draws a histogram
ui <- fluidPage()
server <- function(input, output) {
onStop(function() {
ssh_disconnect(ssh.session)
cat("*** Logging out of the session ***")
})
}
# Run the application
shinyApp(ui = ui, server = server)

failed to match connection hostname (api.shinyapps.io) against server certificate names

when deploying a shiny app, rstudio ide shows the error:
Error in curl::curl_fetch_memory(url, handle = handle) :
schannel: CertGetNameString() failed to match connection hostname (api.shinyapps.io) against server certificate names
Calls: ... tryCatch -> tryCatchList -> tryCatchOne ->
Timing stopped at: 0.02 0.02 0.8
Execution halted
this is for windows 7(64bit).
the details:
----- Deployment log started at 2019-08-03 01:42:06 -----
Deploy command:
rsconnect::deployApp(appDir = "D:/shinyTest/_app002", appFileManifest = "C:/Users/ADMINI~1/AppData/Local/Temp/2013-805c-ca6a-04c2", account = "r00", server = "shinyapps.io", appName = "_app002", appTitle = "_app002", launch.browser = function(url) { message("Deployment completed: ", url) }, lint = FALSE, metadata = list(asMultiple = FALSE, asStatic = FALSE), logLevel = "verbose")
Session information:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.1 rsconnect_0.8.15
Cookies:
[1] "None"
----- Deployment error -----
Error in curl::curl_fetch_memory(url, handle = handle) :
schannel: CertGetNameString() failed to match connection hostname (api.shinyapps.io) against server certificate names
Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
----- Error stack trace -----
20: stop(e)
19: value[[3L]](cond)
18: tryCatchOne(expr, names, parentenv, handlers[[1L]])
17: tryCatchList(expr, classes, parentenv, handlers)
16: tryCatch({
response <- curl::curl_fetch_memory(url, handle = handle)
}, error = function(e, ...) {
if (identical(e$message, "Callback aborted") || identical(e$message,
"transfer closed with outstanding read data remaining"))
return(NULL)
else stop(e)
})
15: system.time(gcFirst = FALSE, tryCatch({
response <- curl::curl_fetch_memory(url, handle = handle)
}, error = function(e, ...) {
if (identical(e$message, "Callback aborted") || identical(e$message,
"transfer closed with outstanding read data remaining"))
return(NULL)
else stop(e)
}))
14: http(service$protocol, service$host, service$port, method, url,
headers, timeout = timeout, certificate = certificate)
13: httpInvokeRequest(..., http = httpFunction())
12: httpRequest(service, authInfo, "GET", path, query, headers, timeout)
11: GET(service, authInfo, path, queryWithList)
10: grepl(contentType, response$contentType, fixed = TRUE)
9: isContentType(response, "application/json")
8: handleResponse(GET(service, authInfo, path, queryWithList))
7: listRequest(service, authInfo, path, query, "applications")
6: client$listApplications(accountInfo$accountId, filters = list(name = name))
5: getAppByName(client, accountInfo, target$appName)
4: applicationForTarget(client, accountDetails, target, forceUpdate)
3: force(code)
2: withStatus(paste0("Preparing to deploy ", assetTypeName), {
application <- applicationForTarget(client, accountDetails,
target, forceUpdate)
})
1: rsconnect::deployApp(appDir = "D:/shinyTest/_app002",
appFileManifest = "C:/Users/ADMINI~1/AppData/Local/Temp/2013-805c-ca6a-04c2",
account = "r00", server = "shinyapps.io", appName = "_app002",
appTitle = "_app002", launch.browser = function(url) {
message("Deployment completed: ", url)
}, lint = FALSE, metadata = list(asMultiple = FALSE, asStatic = FALSE),
logLevel = "verbose")
Error in curl::curl_fetch_memory(url, handle = handle) :
schannel: CertGetNameString() failed to match connection hostname (api.shinyapps.io) against server certificate names
Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Timing stopped at: 0.02 0.02 0.8
Execution halted
can anyone help me? thx!
I had this issue just yesterday and saw the same error when trying to deploy an app. If you're like me, you searched and found that similar errors are observed if you have a proxy server in the way. With that being said, I am assuming that you are not behind a proxy server. If you are, follow some of what is said elsewhere.
I am also assuming that you have previously setup your account via rsconnect::setAccountInfo(). If not, follow the instructions on the rsconnect documentation.
If all that is set, note the text of the error specifies that the issue is actually an error in the curl package:
Error in curl::curl_fetch_memory(url, handle = handle) : schannel: CertGetNameString() failed to match connection hostname
(api.shinyapps.io) against server certificate names
The simple answer would be to update specifically the curl package: install.packages('curl'). That worked for me... does that help?

IBM Data Science Experience (DSX): Using ibmdbR on RStudio

I’ve created a connection to Db2 Warehouse on Cloud: dashDB for Analytics-t1 / Database: BLUDB. I’ve given ‘dashdb connect’ as the connection name.
Then I've selected Tools / RStudio. In RStudio, I've run the following lines. The error message below.
Code snippet:
library(ibmdbR)
con <- idaConnect('BLUDB','','')
#Close the connection
idaClose(con)
Output:
con <- idaConnect('BLUDB','','')
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=BLUDB", believeNRows = FALSE) : [RODBC] ERROR: state 08001, code -30082, message [unixODBC][IBM][CLI Driver] SQL30082N Security processing failed with reason "17" ("UNSUPPORTED FUNCTION"). SQLSTATE=08001
2: In RODBC::odbcDriverConnect("DSN=BLUDB", believeNRows = FALSE) : ODBC connection failed
Your code snippet will only work as is if you run it in the RStudio from the DB2 Warehouse console. If you launch RStudio within DSX you need to configure connectivity. The following worked for me:
install.packages("ibmdbR")
library(ibmdbR)
dsn_driver <- "BLUDB"
dsn_database <- "BLUDB"
dsn_hostname <- "..."
dsn_port <- "50000"
dsn_protocol <- "TCPIP"
dsn_uid <- "..."
dsn_pwd <- "..."
con_path <- paste(dsn_driver,";DATABASE=",dsn_database,";HOSTNAME=",dsn_hostname,";PORT=",dsn_port,";PROTOCOL=",dsn_protocol,";UID=",dsn_uid,";PWD=",dsn_pwd,sep="")
ch <-idaConnect(con_path)
idaInit(ch)
idaShowTables()
Replace "..." with your credentials and you should be good to go.
I followed the instructions from the video named "Connect to dashDB in RStudio" on this page: https://datascience.ibm.com/docs/content/analyze-data/rstudio-overview.html and found the following documentation: https://datascience.ibm.com/blog/dashdb-r-dsx/

Failed to detect version from SPARK_HOME or SPARK_HOME_VERSION

I'm trying to follow a tutorial for using spark from RStudio on DSX, but I'm running into the following error:
> library(sparklyr)
> sc <- spark_connect(master = "CS-DSX")
Error in spark_version_from_home(spark_home, default = spark_version) :
Failed to detect version from SPARK_HOME or SPARK_HOME_VERSION. Try passing the spark version explicitly.
I took the above code snippet from the connect to spark dialog in RStudio:
So I took a look at SPARK_HOME:
> Sys.getenv("SPARK_HOME")
[1] "/opt/spark"
Ok, Lets check that dir exists:
> dir("/opt")
[1] "ibm"
I'm guessing this is the cause of the problem?
NOTE: there are a few similar questions on stackoverflow, but none of them are about IBM's Data Science Experience (DSX).
Update 1:
I tried the following:
> sc <- spark_connect(config = "CS-DSX")
Error in config$spark.master : $ operator is invalid for atomic vectors
Update 2:
An extract from my config.yml. Note that I have many more spark services in my, I've just pasted the first one:
default:
method: "shell"
CS-DSX:
method: "bluemix"
spark.master: "spark.bluemix.net"
spark.instance.id: "7a4089bf-3594-4fdf-8dd1-7e9fd7607be5"
tenant.id: "sdd1-7e9fd7607be53e-39ca506ba762"
tenant.secret: "xxxxxx"
hsui.url: "https://cdsx.ng.bluemix.net"
Note that my config.yml was generated for me.
Update 3:
My .Rprofile looks like this:
# load sparklyr library
library(sparklyr)
# setup SPARK_HOME
if (nchar(Sys.getenv("SPARK_HOME")) < 1) {
Sys.setenv(SPARK_HOME = "/opt/spark")
}
# setup SparkaaS instances
options(rstudio.spark.connections = c("CS-DSX","newspark","cleantest","4jan2017","Apache Spark-4l","Apache Spark-3a","ML SPAAS","Apache Spark-y9","Apache Spark-a8"))
Note that my .Rprofile was generated for me.
Update 4:
I uninstalled sparklyr and restarted the session twice. Next I tried to run:
library(sparklyr)
library(dplyr)
sc <- spark_connect(config = "CS-DSX")
However, the above command hung. I stopped the command and checked the version of sparklyr which seems to be ok:
> ip <- installed.packages()
> ip[ rownames(ip) == "sparklyr", c(0,1,3) ]
Package Version
"sparklyr" "0.4.36"
You cannot use master parameter to connect to bluemix spark service if that is the intent since your kernels are defined in config.yml file, you should be using config parameter instead to connect.
config.yml is loaded up with your available kernel information(spark instances).
Apache Spark-ic:
method: "bluemix"
spark.master: "spark.bluemix.net"
spark.instance.id: "41a2e5e9xxxxxx47ef-97b4-b98406426c07"
tenant.id: "s7b4-b9xxxxxxxx7e8-2c631c8ff999"
tenant.secret: "XXXXXXXXXX"
hsui.url: "https://cdsx.ng.bluemix.net"
Please use config
sc <- spark_connect(config = "Apache Spark-ic")
as suggested in tutorial:-
http://datascience.ibm.com/blog/access-ibm-analytics-for-apache-spark-from-rstudio/
FYI,
By Default, you are connected to , i am working on finding how to change version with config parameter.
> version <- invoke(spark_context(sc), "version")
print(version)
[1] "2.0.2"
Thanks,
Charles.
I had the same issue and fix it as follows:
go to C:\Users\USER_NAME\AppData\Local/spark/ and delete everything you'll find in the directory
Then, in the R console run:
if (!require(shiny)) install.packages("shiny");
library(shiny)
if (!require(sparklyr)) install.packages("sparklyr");
library(sparklyr)
spark_install()

AWS Opsworks using "environment_variables" on Deploy recipes

I want to use the environment_variables of an App to set some properties, but my instance keep failing at setup, reading the documentation (http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-events.html) I found this:
"Setup includes Deploy; it runs the Deploy recipes after setup is complete.".
This is part of my Deploy script
if node['deploy']['ws']['application'] && node['deploy']['ws']['environment_variables']['is_root_app'] == 'true'
web_app node['deploy']['ws']['application'] do
server_name node['fqdn']
server_aliases node['deploy']['ws']['domains']
template 'web_app.conf.erb'
docroot node.default['apache']['docroot_dir']
ssl_enabled node['deploy']['ws']['ssl_support']
enable true
end
end
This is the Setup log
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace:
---------------
/var/chef/runs/254b8caa-cd70-4525-a2fd-71044afdf62d/local-mode-cache/cache/cookbooks/WebService/recipes/deploy_app.rb:8:in `from_file'
Relevant File Content:
----------------------
/var/chef/runs/254b8caa-cd70-4525-a2fd-71044afdf62d/local-mode-cache/cache/cookbooks/WebService/recipes/deploy_app.rb:
1: #
2: # Cookbook Name:: WebService
3: # Recipe:: default
4: #
5: # Copyright (c) 2016 The Authors, All Rights Reserved.
6:
7:
8>> if node['deploy']['ws']['application'] && node['deploy']['ws']['environment_variables']['is_root_app'] == 'true'
9: web_app node['deploy']['ws']['application'] do
10: server_name node['fqdn']
11: server_aliases node['deploy']['ws']['domains']
12: template 'web_app.conf.erb'
13: docroot node.default['apache']['docroot_dir']
14: ssl_enabled node['deploy']['ws']['ssl_support']
15: enable true
16: end
17: else
Whats the purpose of running the Deploy recipes after Setup, if I didnt deployed any App yet??? Where the environment_variables can be used if not on the Deploy recipes???
Imagine you have everything set up and you just start a new machine. It will run setup, configure then deploy otherwise you would end up with an instance that's not ready for production.
deployment fails when you're trying to access attributes that aren't set
You can use http://ruby-doc.org/core-1.9.3/Hash.html#method-i-has_key-3F to check this
e.g.
if node[:deploy].has_key?("ws")
end
Same for your env variables