I have shiny app, which works perfectly fine on my local machine. I deployed the app on shiny-server running on centos-release-6-9.el6.12.3.x86_64. The content of the application is loaded without any graphics as shown below:
And I get the following message in JS consol.
Loading failed for the <script> with source “http://mamged:3838/v01/shared/bootstrap/shim/respond.min.js”. v01:18:1
ReferenceError: Shiny is not defined[Learn More] v01:21:1
Loading failed for the <script> with source “http://mamged:3838/v01/shinyjs/shinyjs-default-funcs.js”. v01:38:1
ReferenceError: shinyjs is not defined[Learn More] v01:39:1
Loading failed for the <script> with source “http://mamged:3838/v01/message-handler.js”. v01:40:1
ReferenceError: jQuery is not defined[Learn More]
[Exception... "Favicon at "http://mamged:3838/favicon.ico" failed to load: Not Found." nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource:///modules/FaviconLoader.jsm :: onStopRequest :: line 156" data: no]
I am not sure what is going wrong.
EDIT
I have put some sample code to reproduce the example on the server.
server.r
# clear console
cat("\014")
# Defining the size of file to be accepted. -1 to accept any size.
options(shiny.maxRequestSize = -1)
# Clear workspace environment
rm(list = ls())
# set locale
Sys.setlocale('LC_ALL','C')
# main function
shinyServer(function(input, output,session) {
})
ui.r
library(shiny)
library(shinyjs)
filenames <- list.files(path = "data",pattern="\\.txt$")
names(filenames) <- gsub(pattern = "\\.txt$", "", filenames)
shinyUI(fluidPage(theme = "bootstrap.css",
(navbarPage("MAMGEDCDE",
position = c("fixed-top"),
fluid = TRUE, selected = "none",
navbarMenu("Help", icon = icon("fa fa-infocircle"),
tabPanel(
list(
a("Reference Manual",
target="_blank", href = "MAMGEDManual.pdf"),
a("GPLs Supported",
target="_blank", href="gpl.pdf"),
a("Video Tutorials",
downloadLink("AbsoluteExpression", " Absolute Expression", class=" fa fa-cloud-download"),
downloadLink("DifferentialExpression", " Differential Expression", class=" fa fa-cloud-download")
)
))
),
navbarMenu("Sample Data",
tabPanel(
list(
downloadLink("AffymetrixData", " Affymetrix", class=" fa fa-cloud-download"),
downloadLink("CodelinkData", " Codelink", class=" fa fa-cloud-download"),
downloadLink("IlluminaData", " Illumina", class=" fa fa-cloud-download")
))
),
navbarMenu("Stand-Alone Version", icon = icon("fa fa-infocircle"),
tabPanel(
list(
downloadLink("CodeandData", " MAMGED", class=" fa fa-cloud-download"),
a("Stand-alone Manual", target = "_blank", href= "Stand-alone.pdf")
)
)
)
)
),
br(),
br(),
useShinyjs(), ## initialize shinyjs to reset input files.
sidebarLayout(
sidebarPanel(
br(),
width = 4,
tabsetPanel(id = "tabs",
tabPanel(id = "tab1", value = "tab1",
h5("Upload Data Files"),
br(),
br(),
fileInput("files", label = "Upload Data Files",
multiple = "TRUE",
accept=c('text/csv','text/comma-separated-values,
text/plain', '.csv','.cel','.TXT','.txt', '.zip')),
uiOutput('Display_source_data'),
br(),
textInput("mailid", "Enter Email ID", placeholder = "Enter your email id")
),
tabPanel(id = "tab2", value= "tab2",
h5("Download Data",style="bold"),
br(),
br(),
br(),
textInput("jobid", "Enter Job ID", placeholder = "Enter your job id")
)),
br(),
br(),
tags$head(tags$script(src = "message-handler.js")),
fluidRow(
conditionalPanel(
condition = "input.tabs == 'tab1'",
column(4,
actionButton("Submit", label = "Submit"))
),
conditionalPanel(
condition = "input.tabs == 'tab2'",
br(),
column(4,
uiOutput("button")
)),
column(4,
actionButton("Reset_Input", label = "Reset"))
),
br()
),
mainPanel(
titlePanel(
headerPanel(
h2( "Analysis of Microarray Gene Expression Data",
align="center", style="bold"
)
)
),
h5("test page")
)
)
))
It works fine on the local machine.
One more thing, do I need to install r packages by using sudo -i R to make it work. I installed all the packages without sudo.
Seems your application is missing a package.
Check your application log by default located in
/var/log/shiny-server.
Also you can add the following option to your config file
/etc/shiny-server/shiny-server.conf:
preserve_logs true; (at the top level)
After a restart of Shiny Server check your log file again.
Look for missing packages or libraries. Hope it helps.
Probably the shiny-server is running as a special user.
Assume the username is like on other servers "www-data".
The problem now is that the files in the web-directory perhaps can be accessed by the shiny-server itself, but not by the clients.
Long story short: adjust the Unix-file-rights for all the files, so that a common client can access the files. This must be done for all files that shall be public available like images, css-files and js-files. Surely it can include any other files too you want to serve like PDF, Office-files, etc.
The unix-rights have to be 0744 for being readable, the last digit is for the public and in your case probably to change with chmod.
For a detailed explanation concerning chmod you can show the man-page on commandline with man chmod.
In some environments it's common that all "public" files are sorted in folders named "public" or "Public", then just the file-rights of these folders have to be changed recursive. Even for the public folders here I use plural, as there can be several folders always with the same name in different directories. On your server the shared folder seems having the same functionality but not all public files are sorted in it. If you prefer the folder name shared over public, you never have to change but only to adjust the rights accordingly.
The reason that I mentioned about the server-user "www-data" above is that the files in the web-directory should have this user as owner, but are not required to be public. All you r-files should be private excepted the files which should be called directly in the browser. So all the files are separated in public and private. The file-owner can be adjusted with chown which can be called on commandline recursive too and with man chown you also can show the detailed description.
About public r-files I don't know if they have to be executable on shiny-servers, if so then the file-rights for these files have to be 0755.
Update
Also assure that all files are existent in your www-directory and that the domain is linked to the right folder.
Related
Here is my code for a simple test app:
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(googledrive)
library(DT)
drive_auth(email = "xxxx")
shinyws1<-gs4_create("WS1")
#table<-read_sheet("xxx")
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Test App"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
numericInput("bins",
"Number of friends:",
min = 1,
max = 100,
value = 50),
actionButton("submit","Submit",class="btn-success")
),
# Show a plot of the generated distribution
mainPanel(
#blank so far
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#results<-reactive(input$bins)
observeEvent(input$submit,{
shinyws1 %>% sheet_append(as.data.frame(input$bins))
})
}
# Run the application
shinyApp(ui = ui, server = server)
It works okay in my local server. But deployment fails.
Here is the error message generated after deployment in Shinyio server:
Error in value[[3L]](cond) : Can't get Google credentials.
Are you running googledrive in a non-interactive session? Consider:
* `drive_deauth()` to prevent the attempt to get credentials.
* Call `drive_auth()` directly with all necessary specifics.
* Read more in: https://gargle.r-lib.org/articles/non-interactive-auth.html
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Does anyone know how to fix it? I've tried every workaround I found online, but it didn't work.
I am quite new to Docker and need to host an R Shiny App on Docker. Any help would be appreciated. Please let me know if I need to change something in the DOckerFile.
R ShinyApp works perfectly fine on a local computer but it crashes while using Docker to host it.I suspect something wrong with the fileInput$datapath and Windows/Docker interaction. Do I need to specify the PATH in the DockerFile?
I have used rocker/verse image from Docker Hub,installed the libraries manually and stored the image locally on my computer as 'r_all_libraries_july2'
This is the image I have used in my DockerFile.
The Shiny Code works well in a Linux environment. But, crashes while running docker in Windows Environment. A temporary file is also getting created in the production environment when a file is input in the Shiny App using fileInput.
library(shiny)
library(DT)
library(dplyr)
library(shinycssloaders)
library(readxl)
library(shinyjs)
library(ggplot2)
library(png)
library(spatstat)
require(tibble)
require(magrittr)
require(dplyr)
require(multcomp)
require(emmeans)
require(readxl)
library(httr)
require(ggfortify)
library(shinyjs)
library(shinyBS)
ui <-navbarPage(title="RShinyApp", windowTitle = "Data Visualization", theme = shinythemes::shinytheme("cerulean"),selected = "Load Data",
tabPanel(title="Load Data", #3rd Tab Panel Start,
fluidPage(useShinyjs(),
sidebarLayout(
sidebarPanel(
wellPanel(checkboxGroupInput("filetype", "Choose filetype to upload:",
choices = c("CSV"="csv", "Excel"="excel"))),
conditionalPanel(condition = "(input.filetype=='csv')|(input.filetype=='excel')",
wellPanel(checkboxInput(inputId = 'header', label = 'Header', value = FALSE)),
fileInput(inputId = "file", label = "Upload File", accept = c(".csv",".xlsx"))
),#End of conditional panel
uiOutput("sheetnames")
#conditionalPanel(condition = "(input.filetype=='excel')&(!is.null(input.file))",uiOutput("sheetnames")),
),#sidebarpanel
mainPanel(
# h3("Data Table"),
withSpinner(tableOutput("contents"))
)
)#SideBarLayout
)#FluidPage End
) #3rd Tab Panel End
)#navbarpage
server <-function(input,output,session){
###########Load Data Tab#######################
rv<-reactiveValues(data=NULL,xlorcsv=NULL,head=FALSE,sheet=NULL,features=NULL)
observeEvent(input$filetype,{if(input$filetype=='csv'){rv$xlorcsv<-'csv'}
else if(input$filetype=='excel'){rv$xlorcsv<-'excel'}})
observeEvent(input$header, rv$head<-input$header)
observeEvent(input$sheetnames,rv$sheet<-input$sheetnames)
observeEvent(input$file,
{if((!is.null(rv$xlorcsv))&(!is.null(input$file))){
#####THIS IS WHERE THE SHINY APP IS CRASHING IN DOCKER--my guess is datapath ###########needs to be defined here
if(rv$xlorcsv=='csv'){rv$data<-read.csv(input$file$datapath, header = rv$head, na.strings = "")
rv$features<-colnames(rv$data)}
}
})
output$sheetnames<-renderUI({
if((is.null(rv$xlorcsv))|(is.null(input$file))){return(NULL)}
if((rv$xlorcsv=='excel')&(!is.null(input$file))){selectInput("sheetnames","Select sheet to load",choices = excel_sheets(path = input$file$datapath))}
})
output$contents<-renderTable({rv$data})
}
shinyApp(server=server, ui=ui)
DockerFile:
FROM r_all_libraries:latest
EXPOSE 80
COPY r_shiny_code_working11.R /home/rstudio/r_shiny_code_working11.R
CMD ["/home/rstudio/r_shiny_code_working11.R"]
This is the error on the console:
standard_init_linux.go:207: exec user process caused "no such file or directory"
I'm posting this because I have not managed to get the solutions posted other places working. I'm trying to re-deploy a shiny dash, but it is failing to install a package at deploy.
It's the BioConductor error, but the package it claims to fail for is a CRAN package, and so I have no idea what to do.
MRE:
library(ggseg); library(shiny); library(tidyverse); library(plotly)
# Define UI ----
ui <- fluidPage(
# Application title
titlePanel("Demonstration of ggseg package"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "atlasChoice", label="Choose atlas",
choiceValues = c("dkt_3d","yeo7_3d",),
choiceNames = c("DKT", "Yeo7"),
inline = FALSE, width = NULL),
radioButtons(inputId = "positionChoice", label="Choose position",
choices = c("LCBC left","LCBC right"),
inline = FALSE, width = NULL)
),
# Show a plot of the generated distribution
mainPanel(
uiOutput("plotUI")
)
)
)
# Define server ----
server <- function(input, output) {
output$plotUI <- renderUI({
plotlyOutput("plotlyPlot")
})
output$plotlyPlot <- renderPlotly({
cc = strsplit(input$positionChoice, " ")[[1]]
ggseg3d(atlas=input$atlasChoice,
surface=cc[1],
hemisphere=cc[2]
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
My repos are set as so:
getOption("repos")
BioCsoft
"https://bioconductor.org/packages/3.7/bioc"
BioCann
"https://bioconductor.org/packages/3.7/data/annotation"
BioCexp
"https://bioconductor.org/packages/3.7/data/experiment"
BioCworkflows
"https://bioconductor.org/packages/3.7/workflows"
CRAN
"https://cran.rstudio.com"
And the error is as following:
Preparing to deploy document...DONE
Uploading bundle for document: 619289...DONE
Deploying bundle: 1770029 for document: 619289 ...
Waiting for task: 573690766
building: Parsing manifest
################################ Begin Task Log ################################
################################# End Task Log #################################
Error: Unhandled Exception: Child Task 573690767 failed:
Error parsing manifest: Unable to determine package source for Bioconductor package oompaBase: Repository must be specified
Execution halted
I don't know if Athanasia's solved this in the end, but I had a similar problem today, so here's what worked for me, in case it's useful for someone else :)
My app uses biomaRt, which I think depends on Biobase. When I tried to deploy, I had the error:
Error: Unhandled Exception: Child Task 601909864 failed: Error parsing manifest: Unable to
determine package source for Bioconductor package Biobase: Repository must be specified
I changed my repos settings based on instructions I found here. This alone also didn't work for me.
Once I reinstalled Biomart using BiocInstaller::biocLite(), my app deployed successfully :)
I am new to R and I am actually developing a page where a directory (string characters like "xx/xx") is given in the server and I want to take back this directory to include it in the source of my ui app.
UI:
library(shiny)
file<-textOutput("paramfile")
source(file(file), local = TRUE, encoding = 'UTF-8')
SERVER :
filedir<-renderText({
"entries/5429_param.R"
})
output$paramfile<-renderText({
filedir()
})
I then have an error :
"Warning in file(filename, "r", encoding = encoding) : cannot open
file '< div id="paramfile" class="shiny-text-output">< /div>':
Invalid argument
Error in file(filename, "r", encoding = encoding) :
cannot open the connection"
Do you know how can I remove those tags or if there is another function that can allow me to take a string in the server and to include it into a source.
Here is a basic example of a ShinyApp:
# Example of UI with fluidPage
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("dir", label = "Enter a directory")
),
mainPanel(
verbatimTextOutput("dirPrint"),
verbatimTextOutput("lsFiles")
)
)
)
# Server logic
server <- function(input, output) {
output$dirPrint <- renderPrint({
print(input$dir)
})
output$lsFiles <- renderPrint({
fls <- list.files(input$dir)
print(fls)
})
}
# Complete app with UI and server components
shinyApp(ui, server)
If you enter the path of a directory in the textinput, the second renderPrint function is showing all files, that are found at that path.
I would suggest you go over the Shiny-Tutorials, as there seem to be some syntax-problems in your code and I am not sure what exactly you want to achieve.
I try to rebuild my application as in the link. I have a multitematic dashboard and I would like to have each topic in separate ui and server files to have better control of the code.
The main file (app.R) is contacting with other files eg UI using source(file.path("ui", "tab1.R"), local = TRUE)$value
tab1.R looks like:
tabPanel("Tab 1", uiOutput("content1")) (content1 is in server file).
I would like to have possibility to put more then on tabPanel in one file. I thought that i can do something like that:
tab1.R looks like:
aaa <- tabPanel("Tab 2", uiOutput("content2"))
bbb <- tabPanel("Tab 1", uiOutput("content1"))
And then contact with them using:
source(file.path("ui", "tab1.R"), local = TRUE)$aaa
source(file.path("ui", "tab1.R"), local = TRUE)$bbb
But i get ERROR:
Error in attr(x, "selected") <- TRUE :
attempt to set an attribute on NULL
I could not find answer for that anywhere so I disated to write here for help
I found imo the best way, I just used the functions:
aaa <- function(){tabPanel("Tab 2", uiOutput("content2"))}
bbb <- function(){tabPanel("Tab 1", uiOutput("content1"))}
And then on the top on file I upload source:
source(file.path("ui", "tab1.R"), local = TRUE)
Now I can normally use functions in code:
aaa()
bbb()