My R works in Ocean Data Bank (ODB), Institute of Oceanography, NTU, Taiwan
Some technical issues about R Shiny application: http://bio.odb.ntu.edu.tw/query
Inter-session delay (async) can be improved by shiny-promises-future framework, and intra-session delay can be improved by memoised function, R.cache example (update 2018/11/13).
Link to database…
Construct shiny-server and PostgresSQL on different server. Write a private, internal package to connect database and return data. Through Opencpu API, then we can can fetch data after users input some criteria in shiny UI, and terminate the link to database after receiving the queried data. Reference link: https://www.opencpu.org/posts/scoring-engine/
Opencpu API can be hidden by Apache and Nginx setting. By doing so, we don’t need to keep connection to database in the shiny session.
Async…
f1 <- reactive({ future( fetchDB1() ) })
f2 <- reactive({ future( fetchDB2() ) })
observeEvent(event, {
df1 <- f1() %...>% ({filtering...}) })
df2 <- f2() %...>% ({filtering...}) })
promise_all(df1, df2) %...>% {
rbindlist(l=., fill=TRUE, use.names=TRUE)
do some controls or side effects here...
}
Loding…
Free free to contact me if any comments.
Some references:
Chinese version, also on ptt https://goo.gl/s9BZT8
Database…
shiny-server 和 PostgresSQL資料庫可架在不同server,在UI 完成篩選條件後,抓資料的function寫成內部使用的package,經由 Opencpu API 去抓使用者要的資料,抓完即斷掉和資料庫連結。 Opencpu API作法參考 https://www.opencpu.org/posts/scoring-engine/
Opencpu server可在Apache 和 Nginx屏蔽成內網使用。用此做法在shiny-server session中,不需要持續和資料庫保持連結。
Async…
Loading…
其實遇到很多問題,都靠孤狗大神一個個解決。我列了我使用到的package在這,其他有機會再續談。 http://bio.odb.ntu.edu.tw/index_tech_citations.html
以上做法可能都有其他更好、更快的方式,目前這樣做僅供參考,也歡迎討論。(如果您有使用此網站,使用經驗上好或不好的地方,或有其他細節要聯絡,敬請告知或透過網頁上email聯絡。)
[關鍵字] Shiny-server, API, Database