Shiny app crashes on Mac in RStudio - r

When I run a Shiny App either an example or my own it starts a new window, freezes and then aborts. It tries to listening to a local port then starts a new session.
Details of my system:
My R version: 3.1.3 on MacOS Maverick
other attached packages:
[1] shiny_0.12.0 Rcpp_0.11.6
loaded via a namespace (and not attached):
[1] digest_0.6.8 htmltools_0.2.6 httpuv_1.3.2 mime_0.3 R6_2.0.1
[6] tools_3.1.3 xtable_1.7-4
What I tried so far:
From different internet forums I found a lot of suggestions:
I reinstalled Rstudio.
I updated all the packages
Tried this: install.packages(c("Rcpp", "httpuv", "shiny"))
Loaded Rcpp and httpuv separately
tried to run like this runApp('app1',host="127.0.0.1",port = 3894)
// tried other ports as well.
But nothing works.
(Please note that, I don't know whether it's relevant but GoogleVis Demo worked on my RStudio.)

#roboticman
My recommendation is first to test and confirm R is correctly setup on your machine. We can then move to harness a Shiny demonstration application and confirm if that works.
https://technophobe01.shinyapps.io/WorldBank/
First step:
Can you please run the following command via R, this should download and install shiny and its dependencies...
> install.packages("shiny", dependencies = TRUE)
If things work after this, great. If not, well, then let's check your R configuration:
Validate R Install
To check your configuration, my recommendation is you launch R on your machine and run the following tests and post back the output.
> R
> sessionInfo()
Sys.setenv(LC_COLLATE = "C", LC_TIME = "C", LANGUAGE = "en")
library("tools")
testInstalledBasic("both")
testInstalledPackages(scope = "base")
testInstalledPackages(scope = "recommended")
testInstalledBasic("internet")
Once you post the output of the above command set, we can move to work through the example 'World Bank', and see if we can determine the problem.
Take care

Try this:
library(shiny)
runExample("01_hello", host = "0.0.0.0", port = 9999).
runApp will also work:
shiny::runApp(host = "127.0.0.1", port = 9999)

Related

Directory not found when using Drat on a network drive

I have developed a package that I want to share with my colleagues at work.
I have a network drive in which I created the local repository structure that looks like this:
MyRepo
\__bin
\__windows
\__contrib
\__src
\__contrib
All folders are empty.
So I built my package with RStudio on Windows using the "Build/More/Build source package" menu, which created a tar.gz file.
Then I tried:
drat::insertPackage("../myPkg_0.0.0.9000.tar.gz",
repodir = "file://networkdrive/path/to/MyRepo",
action = "prune")
But this gives me an error:
Error: Directory file://networkdrive/path/to/MyRepo not found
Which is strange because file.exists(//networkdrive/path/to/MyRepo) returns true.
OK, then I tried:
drat::insertPackage("../myPkg_0.0.0.9000.tar.gz",
repodir = "//networkdrive/path/to/MyRepo",
action = "prune")
Without the file: in the repository path and I get another error:
tar (child): "//networkdrive/path/to/MyRepo/src/contrib/myPkg_0.0.0.9000.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
/usr/bin/tar: Child returned status 2
/usr/bin/tar: myPkg/DESCRIPTION: Not found in archive
/usr/bin/tar: Exiting with failure status due to previous errors
reading DESCRIPTION for package ‘myPkg’ failed with message:
cannot open the connection
But when I go in the "//networkdrive/path/to/MyRepo/src/contrib" folder, I can definitely see the myPkg_0.0.0.9000.tar.gz file that has been copied despite the error message.
Can anyone help?
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] drat_0.1.2 tools_3.3.3 git2r_0.18.0
I know this is old, but my colleague just came across the same problem and found this post. I believe the issue may be the lack of a trailing slash in your directory name. I have been able to recreate the error with a mapped network drive. I can resolve the issue by using "H:/MyRepo/" instead of "H:/MyRepo".
I haven't tried it with the "file://" format, but I wanted to include my answer in case someone else comes across this question.
Ok, so after some research, here is my conclusions.
It cannot be done
It's not Drat's fault
The reason why it does not work is that the tools::write_PACKAGES function does not work on network drives. Period.
I manually copied my package on the network drive, then ran setwd() to its location and executed write_PACKAGES(".", type="source") and I got the same error.
So to make this work, I just left my package.tar.gz file on a local drive, ran the tools::write_PACKAGES command locally and then moved the files to the network drive.
Adding the network drive to my repository list using options(repos = c(MyRepo = "file://networkdrive/path/to/MyRepo/")) works: RStudio and available.packages find my package.
It's not completely satisfactory, but I think it's the only way today.
I was having this problem as well and finally got to the bottom of it today.
For me, the problem was not isolated to just network locations but also occurred on C: drive. The root cause was the version of tar.exe being used to unpack the existing packages in the package directory. Calls to utils::untar are made in the tools::write_PACKAGES function.
The documentation for utils::untar explains that on Windows, external tar.exe is tried first. Sure enough, I had a version installed with Git which when used with default arguments fails when a colon is in the file name. I was able to force utils::untar to use to use the RBuildTools version of tar.exe instead by setting the environment variable TAR to "internal".
drat::insertPackage now works.

Read an Excel file stored on SharePoint from Linux server (running R Studio)

I am trying to read an Excel file that is stored on a corporate intranet SharePoint site, and am doing so using the 'gdata' package from within R Studio run on a Linux server using Shiny Server.
I had good results reading the file from within a MS Windows environment using gdata, but cannot seem to get things to work when running the script on the Linux server. This was based on the info from:
http://r.789695.n4.nabble.com/trying-to-import-xls-or-xlsx-files-td3620580.html
I did modify the R script for the path to Perl on the Linux server (vs. the path to perl.exe on Windows), and this seems to work ok.
The file url is
"http://sharepoint2/ops/quality/metricspc/Metric OptIn List/temporary SPC Metric Opt-In List.xlsm"
Here is the R code:
# R read MS Excel xlsm file from SharePoint
# method using gdata - seems to work with SharePoint
# NOTE: requires 'perl' installed
#
# example from
# http://r.789695.n4.nabble.com/trying-to-import-xls-or-xlsx-files-td3620580.html
library(gdata)
fileurl =
# see fileurl above this code section - did this due to SO error message about not having 'sharepoint2' in the url
d.optin.init2 <- read.xls(fileurl,
sheet = "OPT-IN LIST",
perl = "/usr/bin/perl")
##### END CODE #####
The original (Windows-based) script used perl = "C:\\Perl64\\bin\\perl.exe"
Here is the error message that results (when run from Linux using R Studio on Shiny Server):
d.optin.init2 <- read.xls(fileurl,
+ sheet = "OPT-IN LIST",
+ perl = "/usr/bin/perl")
trying URL 'http://sharepoint2/ops/quality/metricspc/Metric OptIn List/temporary SPC Metric Opt-In List.xlsm'
Error in download.file(xls, tf, mode = "wb") :
cannot open URL 'http://sharepoint2/ops/quality/metricspc/Metric OptIn List/temporary SPC Metric Opt-In List.xlsm'
In addition: Warning message:
In download.file(xls, tf, mode = "wb") :
cannot open: HTTP status was '400 Bad Request'
Error in file.exists(tfn) : invalid 'file' argument
The path to the file (on SharePoint) is a URL (shown in the code), so I thought that the route between the Linux server and MS SharePoint might be straightforward. But since this does work for me with Windows but does not yet work for me with Linux, I wonder what I may have missed?
Thank you in advance for any insight that might be offered.
(I haven't attached the Excel file because I wasn't sure that it would help with this question.)
Best regards,
Cliff
Output from sessionInfo
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
1 C
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 gdata_2.13.3 qcc_2.5
loaded via a namespace (and not attached):
1 MASS_7.3-31 gtools_3.4.1 tools_3.1.0
Acting on the suggestions provided by hrbrmstr and also Greg, I tried both wget and also curl from the Linux command line.
wget results
curl results
I can work with our IT folks to resolve. If anyone can help me to refine the questions I might ask of them based on these results, I would welcome this input.
Thanks again to those who took the time to respond.
MORE FOLLOW-UP
#Gregory R. Warnes
I was able to use wget with this command line from the Linux server:
wget --http-user=myusername --http-passwd=mypassword (place fileurl here)
This seemed to access the file, bridging the divide between Linux server and Windows SharePoint.
Now to figure out how to include this AD authentication in the gdata R script.
The error message indicates that R's download.file() code was not able to access the URL.
To debug the issue, try accessing that URL from the Linux server from the shell command line, for example:
If wget is installed:
> wget http://sharepoint2/ops/quality/metricspc/Metric OptIn List/temporary SPC Metric Opt-In List.xlsm
or if curl is installed:
> curl http://sharepoint2/ops/quality/metricspc/Metric OptIn List/temporary SPC Metric Opt-In List.xlsm
If wget and/or curl generates an error, then you have a server configuration issue.
If wget and/or curl succeed then the problem may be with R's download.file().
-Greg

Shiny runExample Error - Fail to create server

I am trying to play around with Shiny and simply attempted to run the basic out-of-the-box example. No dice.
I attempted to Google the Issue but everything appears to address issues when running it on an external server.
Maybe I am mistaken, but I assumed that this app would run in my browser using localhost.
Here is what I did:
install.packages("shiny")
library(shiny)
runExample("01_hello")
Here is the error:
> runExample("01_hello")
Listening on port 8100
Error in startServer("0.0.0.0", port, httpuvCallbacks) :
Failed to create server
and for completeness sake, here is my session Info:
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_0.7.0
loaded via a namespace (and not attached):
[1] bitops_1.0-5 caTools_1.14 digest_0.6.3 httpuv_1.1.0 RJSONIO_1.0-3 tools_3.0.1 xtable_1.7-1
This error could be because of blocked port.
I was running shiny server on port 3259. I killed the server for some reason and when i was trying to start it again i saw this error.
Error in startServer("0.0.0.0", port, httpuvCallbacks) :
Failed to create server
Calls: runApp -> startAppDir -> startApp -> startServer
To resolve you can first find the process which is blocking your port
First use netstat to view the process blocing your port
netstat -anp|grep :3259[[:blank:]]
and then kill that process
#Hadley's last comment to re-install shiny and httpuv did the trick.
devtools::install_github(c("shiny", "httpuv"), "rstudio")
Actually with re-install you just stopped httpuv server in a difficult way.
what you need to do is only stopServer the current running Server. What happens here is httpuv server is started but it did not stopped for some reason. now that you try to re-run your shiny app you cannot start it again, because it is already started and then you get the mentioned error.
to start your program in this case you can just run service in a loop, you don't need to start server again:
while (TRUE) {
.Call("httpuv_run", PACKAGE = "httpuv", 250)
Sys.sleep(0.001)
}
Though you also can stop previous server and start it again using:
stopServer(server)
however in this case you need to know where server variable is stored.

Can't use either View() or edit() functions, getting "Error in .External2(C_dataviewer, x, title) : invalid device" error message

I'm running R through the Terminal in a Mac OSX Snow Leopard system.
I get this error message when trying to use View():
Error in .External2(C_dataviewer, x, title) : invalid device In
addition: Warning messages: 1: In View(a) : locale not supported by
Xlib: some X ops will operate in C locale 2: In View(a) : X cannot set
locale modifiers 3: In View(a) : unable to create fontset
--fixed-medium-r----120------
And this error message when trying to use edit():
Error in .External2(C_dataentry, datalist, modes) : invalid device In
addition: Warning messages: 1: In edit.data.frame(a) : locale not
supported by Xlib: some X ops will operate in C locale 2: In
edit.data.frame(a) : X cannot set locale modifiers 3: In
edit.data.frame(a) : unable to create fontset
--fixed-medium-r----120------
I can't find information about this particular problem. What can I do to fix this?
sessionInfo() returns:
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] C/UTF-8/C/C/C/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
The problem might be your locale settings. Run command 'locale' from terminal and see if there are any lines with something else but 'C' locale. For example, in my case output is like this:
macbook:foo user$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
Easiest way to solve this is to set the locale to be C for just the R process ie. run R from terminal session with command 'LC_CTYPE=C R' instead of just 'R'. At least on OS/X 10.6.8 this gets rid of the error messages and allows R to display the edit window.
The cause for my problem: View(dataset) in the rchunk where we load up data.
I had it here because I loaded in data like data <-read_excel("name")
And had View there because I copied and pasted it from my console, but it's not needed.
Experienced this with RStudio Server. I just had to restart R (Ctrl/Cmd + Shift + F10) to get rid of the error.
It was possibly caused by updating some packages.
if you download the xquart, I think you need to restart your Mac to activate its work.
I had the same problem just a few minutes ago and I restart my Mac, now it works.
I had the same error in RStudio. I'm not certain if this would be the same for using R via the Terminal, but for RStudio users who get this message using the jagsUI package masks the View function which triggers this warning. See this question
Easiest workaround seems to be to call detach("package:jagsUI", unload = TRUE) once you have finished using JAGS.
Check potential conflicts between functions by calling conflicts(detail=TRUE) (Taken from this answer for finding which functions are masked in R).

R .libPaths() difference between RStudio and command-line R

When I run R from the command line:
> library(ggplot2)
...
> path.package('ggplot2')
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13/ggplot2"
> .libPaths()
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
> Sys.getenv('R_LIBS_USER')
[1] "~/R/x86_64-pc-linux-gnu-library/2.13"
(Note: that environment variable actually doesn't exist when I check from my shell.)
But from RStudio Server running on the same box, and after logging in as the same user:
> path.package('ggplot2')
[1] "/home/yang/R/library/ggplot2"
> .libPaths()
[1] "/home/yang/R/library" "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library" "/usr/lib/R/library"
[5] "/usr/lib/rstudio-server/R/library"
> Sys.getenv('R_LIBS_USER')
[1] "/home/yang/R/library"
Can you explain why these are different by default? Is this an RStudio customization? (Why?) Thanks in advance.
Direct answer from the source:
http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r
Hi there,
Yes, we have a custom R_LIBS_USER setting which is intended to make it
easier to upgrade the server to a new version of R without requiring
that every user rename their library directory and/or re-build their
packages. That way the administrator can do an upgrade without fearing
that they'll break their user's working environment (realize that this
could also be accomplished by writing an upgrade script that does the
requisite rename/rebuild for each user).
Fully agree that this isn't necessarily desirable in all cases. Here
is what you can do to work around it:
The Rtudio Server R_LIBS_USER is controlled by the following setting
in /etc/rstudio/rsession.conf:
r-libs-user=~/R/library
This variable supports the same wildcarding as R_LIBS_USER (as
described here:
http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html)
so you could change this to the following to make RStudio behave just
like console R:
r-libs-user=~/R/%p-library/%v
(note I believe that is the right syntax to reproduce the directory
shown in your output above but you'll definitely want to double check
that)
Hope that clears things up and that you can get things configured as
you'd like. Let us know if you have other questions or if this doesn't
work as described.
J.J.
A quick googling got me here:
http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths
so it looks like RStudio uses its own libs, set in /etc/rstudio/rsession.conf. Why? Who knows.

Resources