[问题] shiny使用循环跑多组模型并依序输出

楼主: aee36900 (持久战!!)   2015-11-30 12:00:45
文章分类提示:
- 问题: 当你想要问问题时,请使用这个类别
[问题类型]:
程式咨询(我想用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
选择性,也许未来有用
作者: celestialgod (天)   2015-11-30 12:16:00
楼主: aee36900 (持久战!!)   2015-12-01 22:07:00
感谢c大的范例,不过怎样可以横向输出阿...目前输出了十组图形,但是都是从上往下
作者: celestialgod (天)   2015-12-01 22:10:00
不是我的范例,google到的@@横向,我也不知道耶QQ,感觉只能调list顺序
楼主: aee36900 (持久战!!)   2015-12-02 10:59:00
有找到splitLayout这个可以横向输出,但是SEREVR那边不知道怎么将循环依序产生的图丢去UI那边呈现

Links booklink

Contact Us: admin [ a t ] ucptt.com