前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R语言shiny之导航栏(navbar)和侧边栏(sidebar)小例子

R语言shiny之导航栏(navbar)和侧边栏(sidebar)小例子

作者头像
用户7010445
发布2020-05-26 10:24:29
2.7K0
发布2020-05-26 10:24:29
举报

在Y叔的公众号看到文章**《有人基于AnnotationHub和clusterProfiler做了个shiny,就能支持1700+的物种,你却老是在问我,非模式生物怎么办!》**。正好自己最近在学习R语言的shiny。于是找到这个shiny的代码看了看,发现不是很长,花点时间应该可以重复出来。

原本的shiny对应的github主页

https://github.com/sk-sahu/sig-bio-shiny

今天先重复一小部分

包括

  • 导航栏
  • 侧边栏
  • 文本输入框
  • 数字输入框
  • 选择框
  • 提交按钮

基本功能是侧边栏输入文本,在主界面以表格的形式展示出来,而且还可以把过程分为好几个步骤,这里用到的代码是

withProgress(message = "Steps:",value = 0,{incProgress(1/7,detail = paste0("Waitting","1")),incProgress(2/7,detail = paste0("Waitting","2"))}
ui代码

ui可以简单理解为前端页面

library(shiny)
ui<-navbarPage('Pomegranate',inverse = T,collapsible = T,
               tabPanel("Gene Ontology",
                        sidebarLayout(
                          sidebarPanel(width = 2,textAreaInput("text_area_list",
                                                               label = "Please input protein id, one per line",
                                                               height = "200px",
                                                               width="180px",
                                                               value="Pg00001"),
                                       selectInput('id_type',label="Input gene-id Type:",
                                                   selected = "A",choices = c("A","B","C")),
                                       helpText("You are!"),
                                       numericInput("pval_cutoff",label = "pvalue-Cutoff",
                                                    value=1,min = 0.001,max=1,step = 0.001),
                                       numericInput("qval_cutoff",label="qvalue-CutOff",value=1,
                                                    min = 0.001,max=1,step=0.001),
                                       hr(),
                                       helpText("After submit it may take 1-2 minutes. Check Progress bar in right side cornor"),
                                       actionButton("submit",label = "Submit",icon=icon('angle-double-right')),
                                       tags$hr()),
                          mainPanel(
                            helpText("Note: After submit it may take 1-2 minutes. Check Progress bar in right side cornor."),
                            tags$hr(),
                            textOutput("gene_number_info"),
                            tags$hr(),
                            DT::dataTableOutput(outputId = "gene_number_info_table")
                          )
                        )))
server代码

server可以理解为后端数据处理逻辑

server<-function(input,output){
  observeEvent(input$submit,{
    withProgress(message = "Steps:",value = 0,{
      incProgress(1/7,detail = paste0("Waitting","1"))
      text_area_input <- input$text_area_list
      df<-as.data.frame(matrix(unlist(stringr::str_split(text_area_input,"\n")),ncol=1))
      print(class(text_area_input))
      print(text_area_input)
      incProgress(2/7,detail = paste0("Waitting","2"))
      output$gene_number_info<-renderText({
        paste0("A","B")
      })
      output$gene_number_info_table<-DT::renderDataTable({
        DT::datatable(df)
      })
    })
  })
}

shinyApp(ui=ui,server=server)
运行的效果
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-05-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 原本的shiny对应的github主页
  • 今天先重复一小部分
  • ui代码
  • server代码
  • 运行的效果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档