【发布时间】:2017-02-15 10:54:15
【问题描述】:
我正在尝试制作一个闪亮的应用程序,该应用程序在不同的行上显示多个图,并允许用户通过使用位于图形旁边的单选按钮来选择正确的趋势。问题是我无法直接在地块旁边找到单选按钮。
我想要:
我的代码:
服务器.R:
library(shiny)
shinyServer(function(input, output) {
lapply(1:3, function(iter) {
output[[paste0("g",iter)]] <- renderPlot({
set.seed(iter)
xx <- rnorm(10)
yy <- rnorm(10)
plot(xx,yy)
abline(reg=lm(yy~xx), col=2, lwd=ifelse(input[[paste0("radio",iter)]]==1,2,1))
abline(reg=lm(yy~xx+0), col=3, lwd=ifelse(input[[paste0("radio",iter)]]==2,2,1))
})
})
})
ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel("My loop test"),
fluidRow(
column(6,
lapply(1:3, function(iter) {
plotOutput(paste0("g",iter))
}
)),
column(3,
lapply(1:3, function(iter){
radioButtons(paste0("radio",iter),label = "buttons", choices = list("with intercept"=1,"without intersept"=2),selected = 1)
}
))
)
))
我希望它很清楚。我是 Shiny 的新手(但不是 R),我仍处于学习曲线的陡峭部分!
谢谢
【问题讨论】:
-
绘图的默认高度为 400px,因此您可以将单选按钮放在 div 或其他具有相同高度的容器中。