shiny - 在 Shiny 中将输入下拉菜单作为侧边栏
问题描述
我想将我的输入面板作为左侧的侧边栏,而不是在下方。我试过了,sidebarLayout
但确实让它工作了。有什么建议么?
输入
dput(df1.t)
structure(list(`hsa-let-7a-3p` = c(5.58182112427671, 5.21705272399953,
5.42864356356758, -1.1383057411356, 5.06203248358181), `hsa-let-7a-5p` = c(17.0260439263402,
15.2857710138151, 17.1420214989373, 15.1034766165351, 14.5449390552056
), `hsa-let-7b-3p` = c(4.28580929310353, 2.46805733598209, 5.15298557165018,
4.63298501632773, -0.398732335974934), `hsa-let-7b-5p` = c(13.0477955183433,
10.880357260433, 12.2652935281359, 11.1312184397251, 7.45844929748327
), `hsa-let-7c-3p` = c(-1.25421892418566, -1.27175388669896,
-1.33049811927568, -1.1383057411356, 2.24661989371122)), class = "data.frame", row.names = c("86",
"175", "217", "394", "444"))
dput(df2.t)
structure(list(A1BG = c(-1.19916952580483, -3.10305950914023,
-3.10305950914023, -3.10305950914023, -0.982321345582416), `A1BG-AS1` = c(0.102743641800478,
-2.24464338564074, -3.10305950914023, -1.92943473454654, -0.652692243977369
), A1CF = c(-3.10305950914023, -2.24464338564074, -2.18375470186949,
-1.92943473454654, -2.30044547836697), A2M = c(3.42115035042484,
-0.0469232989985426, 6.84141032645296, 5.78124672930663, 2.53353451576527
), `A2M-AS1` = c(-2.03481283871687, -3.10305950914023, -2.18375470186949,
-3.10305950914023, -2.64664301822906)), class = "data.frame", row.names = c("86",
"175", "217", "394", "444"))
脚本
ui <- fluidPage(
titlePanel("MicroRNA-mRNA correlation plot"),
mainPanel(
plotOutput("plot")
),
selectInput(inputId ="data1",
label = "Choose Gene",
choices = names(df2.t),
selected = NULL
),
selectInput(inputId ="data2",
label = "Choose MicroRNA",
choices = names(df1.t),
selected = NULL
),
textOutput("result"))
server <- function(input,output){
data <- eventReactive(c(input$data1,input$data2),{
data <- data.frame(df1.t[[input$data2]], df2.t[[input$data1]])
colnames(data) <- c("col1", "col2")
data
})
output$plot <- renderPlot({
ggplot(data(),aes(x=col2,y=col1)) +
geom_point(colour='black') +
labs(x = paste(input$data1,"(cpm, log2)"), y = paste(input$data2,"(cpm, log2)")) +
theme_classic(base_size = 12) +
geom_smooth(method="lm",se = F) +
stat_cor()
}, height = 400, width = 600)
}
shinyApp(ui=ui,server=server)
解决方案
尝试这个:
ui <- fluidPage(
titlePanel("MicroRNA-mRNA correlation plot"),
sidebarLayout(
sidebarPanel(
selectInput(inputId ="data1",
label = "Choose Gene",
choices = names(df2.t),
selected = NULL
),
selectInput(inputId ="data2",
label = "Choose MicroRNA",
choices = names(df1.t),
selected = NULL
)
),
mainPanel(
plotOutput("plot"),
textOutput("result")
)
)
)
推荐阅读
- php - 如何使用 substr_replace 在字符串的多个位置替换或插入字符,我可以在函数上添加多个位置吗?
- ruby-on-rails - 如何将 git 添加到 ruby 命令行?
- c# - Bot Framework C#,添加小键盘
- ios - 我可以将 SwiftNIO 客户端 websocket 与不同的服务器 websocket 一起使用吗?
- javascript - VueJS 何时使用 id 和 class
- python - 如何将正则表达式结果拆分为多列(Python)
- javascript - 有没有办法只检查一个普通的 javascript 对象而不是任何其他特殊类型的对象(即日期)?
- ios - 如何在 UIView 中创建椭圆形清晰的颜色视图?
- asp.net - 不能应用于“IEnumerable”类型的操作数
' 和 `DateTime` ( >= & <=) - kubernetes - 如果我使用 Istio 进行映射,我需要大使吗?