I am wondering why shinyapps.io no longer can connect to a mongoDB from Atlas. I have done countless projects using mongoAtlas and shinyapps.io.
As of today, any new app I publish does not allow me to connect to my mongoDB.
In my logs I get an error:
No suitable servers found (serverSelectionTryOnce
set): [socket timeout calling ismaster on 'cluster0-shard-00-00-02dsl.mongodb.net:27017']
The code runs perfectly on Rstudio Cloud, my local pc and my friends local pc. But shinyapps.io is having a hard time.
UI.R
library(mongolite)
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
tableOutput("table")
)
)
))
Server.R
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
url = "mongodb://jwrong:<mypass>@cluster0-shard-00-00-02dsl.mongodb.net:27017,cluster0-shard-00-01-02dsl.mongodb.net:27017,cluster0-shard-00-02-02dsl.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=false"
df.orats = mongo(collection = "df.orats", db = "test", url = url, verbose = T)
d = df.orats$find()
output$table <- renderTable({
d
})
})
You can try now. Probably, there was some issue with MongoDB or shinyapps.io. Rather the second one. Now everything works.