[問題] shiny使用迴圈跑多組模型並依序輸出

看板R_Language作者 (持久戰!!)時間10年前 (2015/11/30 12:00), 編輯推噓0(007)
留言7則, 2人參與, 最新討論串1/1
文章分類提示: - 問題: 當你想要問問題時,請使用這個類別 [問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 請把以下不需要的部份刪除 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 想要使用shiny跑多組不同參數設定的模型 然後layout server端的output不知道如何使用迴圈代替 [程式範例]: 程式有做些簡化 ui的設計如下 library(shiny) shinyUI(fluidPage( headerPanel("model"), sidebarLayout( sidebarPanel( selectInput("city", "choice a city:", list("...")) submitButton("Update View") ), mainPanel( splitLayout( plotOutput("ns_plot1"), plotOutput("ns_plot2"), plotOutput("ns_plot3"), plotOutput("ns_plot4"), plotOutput("ns_plot5") ) ) ))) server的設計如下 #由前端接收參數當作SQL的條件 然後去impala撈資料 #接著在renderPlot中 跑模型並畫出圖形行輸出至前端 library(shiny) library(RImpala) shinyServer(function(input, output) { datainput <- reactive({ sql_query <- paste(...) rimpala.init() rimpala.connect() impala_dataset <-rimpala.query(sql_query) rimpala.close() m2 <- impala_dataset }) i <- 1 while (i<6){ output$ns_plot(i) <- renderPlot({ m2 <- datainput() cb.ns <- crossbasis(..., argvar=list(fun="ns",df=(i)),...) model.ns <- glm(visits ~ cb.ns + dow,family=quasipoisson(), m2) pred.ns <- crosspred(cb.ns ,model.ns ) plot(predns, xlab="air factors", zlab="RR", theta=200, phi=40, lphi=30) }) }}) [環境敘述]: R version 3.2.1 (2015-06-18) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: CentOS release 6.7 (Final) [關鍵字]:shiny loop polt splitLayout 選擇性,也許未來有用 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.76.246.58 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1448856048.A.139.html

11/30 12:16, , 1F

12/01 22:07, , 2F
感謝c大的範例,不過怎樣可以橫向輸出阿...
12/01 22:07, 2F

12/01 22:08, , 3F
目前輸出了十組圖形,但是都是從上往下
12/01 22:08, 3F

12/01 22:10, , 4F
不是我的範例,google到的@@
12/01 22:10, 4F

12/01 22:11, , 5F
橫向,我也不知道耶QQ,感覺只能調list順序
12/01 22:11, 5F

12/02 10:59, , 6F
有找到splitLayout這個可以橫向輸出,但是SEREVR那邊不
12/02 10:59, 6F

12/02 10:59, , 7F
知道怎麼將迴圈依序產生的圖丟去UI那邊呈現
12/02 10:59, 7F
文章代碼(AID): #1MMydm4v (R_Language)
文章代碼(AID): #1MMydm4v (R_Language)