R Shiny GoogleSheets4: Authentication error in Shinyio server on deployment? - r

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.

Related

Shiny app runs locally, error when trying to deploy it

I am getting an error
The application failed to start: exited unexpectedly with code 1
Error in enforcePackage(name, curVersion) :
The shiny package was not found in the library.
Calls: local ... eval -> eval -> eval -> -> enforcePackage
Execution halted
when I try to deploy shiny app. I found similar problem that claimed that having library(shiny) solves it, it didn't help. I also tried lib=("path/to/shiny"), no effect.
Here is my code
library(shiny)
library(DT)
library(rmarkdown)
###
ui <- fluidPage(fluidRow(column(10, div(dataTableOutput("dataTable")))))
server <- function(input, output, session) {
data <- reactiveFileReader(100, session, 'excel.csv', read.csv)
output$dataTable <- renderDT(
data(),
class = "display nowrap compact",
filter = "top",
options = list(
scrollX = TRUE,
searchCols = default_search_columns,
search = list(regex = FALSE, caseInsensitive = FALSE, search = default_search)
)
)
}
shinyApp(ui, server)
rsconnect::deployApp('C:/path//app1.Rmd')
Any help is appreciated.
The error indicates that Shiny is not installed in the environment you are deploying to.
If deploying to a server you own, first install Shiny Server, and confirm that the examples work as expected.
Then consult with the Administrator's Guide to set it up as you like it.

R - shiny app - ERROR: Invalid git repo specification: 'ShinySky'

I try to run a shiny app on R studio, I get the error
"ERROR: Invalid git repo specification: 'ShinySky'"
with the message at the console:
"there is no package called ‘shinysky’
Warning: Error in parse_repo_spec: Invalid git repo specification: 'ShinySky'"
Any ideas how to resolve the issue?
install.packages("shiny")
library(shiny)
ui <- fluidPage(
sliderInput(inputId ="num", label = "Choose the sample size", value=5,
min=1, max=25 ),
plotOutput("hist")
)
server <- function(input, output, session) {
output$hist <- renderPlot({
hist(rnorm(input$num))
})
}
shinyApp (ui, server)

Store user-upload file to specified local folder

I want to create an app where User A uploads a file to server and User B can download it to a local folder.
I am first implementing the actions of uploading the file, and then immediately store that file to my own specified folder (since I am the sole User here). This is the code:
library(shiny)
ui <- fluidPage(
fileInput('file1', 'Choose csv File',
accept=c('text/csv'))
)
server <- function(input , output){
rootDir <- 'C:/RShiny/Dir'
inFile <- reactive({input$file1})
file.copy(inFile()$datapath,
file.path(rootDir, inFile()$name, fsep = .Platform$file.sep))
}
shinyApp(ui = ui , server = server)
However, I keep receiving this error message:
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
53: stop
52: .getReactiveEnvironment()$currentContext
51: getCurrentContext
50: .dependents$register
49: inFile
47: server [C:\RShiny\.../app.R#12]
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
And the app just closes right away. Not sure what it means and how to fix it. If someone could help explaining?
Thanks,
Please try the below:
library(shiny)
ui <- fluidPage(
fileInput('file1', 'Choose csv File',
accept=c('text/csv'))
)
server <- function(input , output){
rootDir <- 'C:/RShiny/Dir'
inFile <- reactive({input$file1})
observe({
file.copy(inFile()$datapath,
file.path(rootDir, inFile()$name, fsep = .Platform$file.sep))
})
}
shinyApp(ui = ui , server = server)
You need to put the file.copy() code in an observe ("a reactive expression or observer").

fileInput not working properly with Docker Windows system

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"

Shinyapps.io deploy fails on package install

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 :)

Resources