效果:
变量1和变量2变化时,下面的显示也会实时更新。
代码:
library(shiny)
library(shinyjs)
library(shinyBS)
ui <- fluidPage(
tags$style(HTML(" input:invalid { background-color: #FFCCCC; }")),
#### Set up shinyjs ####
useShinyjs(),
### shinyBS ###
bsAlert("alert"),
numericInput("myValue", "My Variable", min = 0, max = 1, value = 0.5),
numericInput("myValue2", "My Variable2", min = 0, max = 3, step = 0.5, value = 0.5),
textOutput("text"),
textOutput("text2")
)
server <- function(session, input, output) {
output$text <- renderText({
### shinyBS ###
if(!(is.na(input$myValue)) && (input$myValue > 1 | input$myValue < 0)) {
createAlert(session, "alert", "myValueAlert", title = "shinyBS: Invalid input",
content = "'My Variable' must be between 0 and 1", style = "danger")
} else {
closeAlert(session, "myValueAlert")
return(input$myValue)
}
})
output$text2 <- renderText(input$myValue2)
### modalDialog ###
observeEvent(input$myValue, {
if(!is.na(input$myValue) && (input$myValue > 1 | input$myValue < 0)) {
showModal(modalDialog(
title = "modalDialog: Invalid input",
"'My Variable' must be between 0 and 1"
))
}
})
### shinyjs ###
observeEvent(input$myValue, {
if(!(is.na(input$myValue)) && (input$myValue > 1 | input$myValue < 0)) {
alert("shinyJS: 'My Variable' must be between 0 and 1")
}
})
}
shinyApp(ui, server)
eg2symbol=toTable(org.Hs.egSYMBOL)
eg2name=toTable(org.Hs.egGENENAME)
eg2alias=toTable(org.Hs.egALIAS2EG)
eg2alis_list=lapply(split(eg2alias,eg2alias$gene_id),function(x){paste0(x[,2],collapse = ";")})
GeneList=mappedLkeys(org.Hs.egSYMBOL)
GeneList[1]
if( GeneList[1] %in% eg2symbol$symbol ){
symbols=GeneList
geneIds=eg2symbol[match(symbols,eg2symbol$symbol),'gene_id']
}else{
geneIds=GeneList
symbols=eg2symbol[match(geneIds,eg2symbol$gene_id),'symbol']
}
geneNames=eg2name[match(geneIds,eg2name$gene_id),'gene_name']
geneAlias=sapply(geneIds,function(x){ifelse(is.null(eg2alis_list[[x]]),"no_alias",eg2alis_list[[x]])})
save(geneAlias,file="D:/gene.alias.RData")
library("gridtext")
网友评论