对于许多专家来说这听起来很容易,但是花了好几个小时后我还没有想出一个合适的解决方案,我可能忽略了一些易于配置的东西。
我的问题是如何使这个闪亮的应用程序与云关系数据库交谈,例如Google MySQL服务,部署到shinyapps.io后
我已经在我的Windows 7 64位计算机上成功启动了这个闪亮的应用程序,因为我已经使用正确的驱动程序MySQL ODBC 5.3 ANSI驱动程序将用户DSN 指定为 google_sql ,ip,密码等,所以在代码行odbcConnect
我可以简单地提供dsn,用户名和密码来打开连接。然而,当我将它部署到shinyapps.io时,它失败了我的期望。我的猜测是我的DSN google_sql无法被shinyapps.io识别,所以为了让它正常工作,我该怎么办?我应该更改一些代码吗?或者在shinyapps.io上配置
server.R
library(shiny)
# library(RODBC)
library(RMySQL)
# ch <- odbcConnect(dsn = "google_sql", uid = "abc", pwd = "def")
ch <- dbConnect(MySQL(),user='abc',password='def',
host = 'cloud_rdb_ip_address', dbname = 'my_db')
shinyServer(function(input, output) {
statement <- reactive({
if(input$attribute == 'All'){
sprintf("SELECT * FROM test_db WHERE country = '%s' AND item = '%s' AND year = '%s' AND data_source = '%s'",
input$country,input$item,input$year,input$data_source)
}else{
sprintf("SELECT * FROM test_db WHERE country = '%s' AND item = '%s' AND attribute = '%s' AND year = '%s' AND data_source = '%s'",
input$country,input$item,input$attribute,input$year,input$data_source)
}
})
output$result <- renderTable(dbFetch(dbSendQuery(ch, statement=statement()),n=1000))
})
ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
headerPanel("Sales Database User Interface"),
fluidRow(
column(4,
selectInput('country','Country',c('United States','European Union','China'),selected = NULL),
selectInput('item','Item',c('Shoes','Hat','Pants','T-Shirt'),selected = NULL),
selectInput('attribute','Attribute',c('All','Sales','Procurement'),selected = NULL)
),
column(4,
selectInput('year','Calendar Year',c('2014/2015','2015/2016'),selected = NULL),
selectInput('data_source','Data Source',c('Automation','Manual'),selected = NULL)
)
),
submitButton(text = "Submit", icon = NULL),
# Sidebar with a slider input for the number of bins
# Show a plot of the generated distribution
mainPanel(
tableOutput("result")
)
))
我认为值得发布我的shiny showLogs()
错误日志专家来启发我,
2015-05-04T06:32:16.143534+00:00 shinyapps[40315]: R version: 3.1.2
2015-05-04T06:32:16.392183+00:00 shinyapps[40315]:
2015-05-04T06:32:16.143596+00:00 shinyapps[40315]: shiny version: 0.11.1
2015-05-04T06:32:16.392185+00:00 shinyapps[40315]: Listening on http://0.0.0.0:51336
2015-05-04T06:32:16.143598+00:00 shinyapps[40315]: rmarkdown version: NA
2015-05-04T06:32:16.143607+00:00 shinyapps[40315]: knitr version: NA
2015-05-04T06:32:16.143608+00:00 shinyapps[40315]: jsonlite version: NA
2015-05-04T06:32:16.143616+00:00 shinyapps[40315]: RJSONIO version: 1.3.0
2015-05-04T06:32:16.143660+00:00 shinyapps[40315]: htmltools version: 0.2.6
2015-05-04T06:32:16.386758+00:00 shinyapps[40315]: Using RJSONIO for JSON processing
2015-05-04T06:32:16.386763+00:00 shinyapps[40315]: Starting R with process ID: '27'
2015-05-04T06:32:19.572072+00:00 shinyapps[40315]: Loading required package: DBI
2015-05-04T06:32:19.831544+00:00 shinyapps[40315]: Error in .local(drv, ...) :
2015-05-04T06:32:19.831547+00:00 shinyapps[40315]: Failed to connect to database: Error: Lost connection to MySQL server at 'reading initial communication packet', system error: 0
2015-05-04T06:32:19.831549+00:00 shinyapps[40315]:
PS:我想我需要将shinyapps.io ip地址列入我的Google可以,以便在shinyapps.io上启用部署。
答案 0 :(得分:3)
我实际上已经设法自己想出这个问题的答案,但是想分享答案,因为它也可能与其他人有关。
以下是白名单所需的IP地址。
54.204.29.251
54.204.34.9
54.204.36.75
54.204.37.78
答案 1 :(得分:2)
pidig89's answer中给出的列表是正确的IP列表,但您可以在其支持网站上找到最新列表,而不是信任SO答案中的一些随机列表:{{3} }
(他们“正式”宣布这是https://support.rstudio.com/hc/en-us/articles/217592507-How-do-I-give-my-application-on-shinyapps-io-access-to-my-remote-database-中帖子上邮件列表列入白名单的推荐方式
答案 2 :(得分:0)
如果你认为这是一个将你的IP列入白名单的shinyapps问题(我不是说这是实际的问题,但是如果是的话)那么我会发布到shinyapps谷歌组,因为shinyapps开发人员监控它并经常回答