I've seen several posts about this but in my ignorance cannot understand (1) if what I want to do is possible, and (2) if someone has solved it.
I am trying to deploy a Shiny app which uses the scholar package using shinyapps.io. A MWE of my app looks something like this:
library(shiny)
library(scholar)
library(dplyr)
library(ggplot2)
scholar_id <- "B7vSqZsAAAAJ"
auth <- get_profile(scholar_id)
pubs <- get_publications(id=scholar_id)
h_index <- auth$h_index
num_pubs <- nrow(pubs) # get number of publications
tot_cites <- sum(pubs$cites) # get total number of citations
# Get num. publications per year
pubYears <- data.frame("year" = pubs$year)
pubYears <- pubYears %>% group_by(year) %>% count(year)
# Get citations per year
citesYear <- get_citation_history(scholar_id)
citesYear$cumulativeCites <- cumsum(citesYear$cites)
# Publication summary
df <- data.frame("num_pubs" = num_pubs,
"h_index" = as.numeric(h_index),
"tot_cites" = as.numeric(tot_cites))
# Begin shiny app -----
ui <- fluidPage(
## Publication summary -----
titlePanel("Article Publication Summary"),
mainPanel(
# Output table as first result
tableOutput('table'),
fluidRow(splitLayout(cellWidths = c("50%", "50%"),
plotOutput(outputId = 'plotYears'),
plotOutput(outputId = 'citeYears')
)
)
)
)
# Define server logic
server <- function(input, output){
output$table <- renderTable({
df
})
output$plotYears <- renderPlot({
p_years <- ggplot(pubYears, aes(year, n))+
geom_col(colour="black",fill="#3399CC")+
scale_x_continuous(name = "Year")+
scale_y_continuous(name = "No. publications")+
theme(panel.grid = element_blank(),
panel.background = element_rect(colour="#595959", fill = NA),
aspect.ratio=1)
p_years
})
output$citeYears <- renderPlot({
p_cites <- ggplot(citesYear, aes(year, cumulativeCites))+
geom_line(colour = "#3399CC")+
geom_point(shape = 21, fill = "#3399CC", colour = "#595959")+
scale_x_continuous(name = "Year")+
scale_y_continuous(name = "Total no. citations")+
theme(panel.grid = element_blank(),
panel.background = element_rect(colour="#595959", fill = NA),
aspect.ratio=1)
p_cites
})
output$network <- renderPlot({
})
}
# Run the app -----
shinyApp(ui = ui, server = server)
When I run this locally on my system, everything works great. However, when I try to deploy this via the shinyapp.io I get an error page saying:
An error has occurred
The application failed to start.
exit status 1
When I check the logs on shinyapps.io I can see:
Warning in get_scholar_resp(url, attempts_left - 1) :
Cannot connect to Google Scholar. Is the ID you provided correct?
Error in auth$h_index : $ operator is invalid for atomic vectors
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
I'm guessing there is some kind of permission problem where Google isn't allowing the web app access? This is referenced by another person here agbarnett/scholar.shiny and someone else likewise asked about the same problem here stackoverflow.com/questions/70226796.