r - 选择输入启用或禁用操作按钮 - 有问题
问题描述
解决方案
试试这个
ui <- fluidPage(
shinyjs::useShinyjs(),
fluidRow(
column(8,offset = 3,
h2("Gene_FPKM Value Barplot")
)
),
fluidRow(
column(8,offset = 3,
selectInput(
"selectGeneSymbol",
"Select Gene Symbol:",
choices = unique(data_mean_sd$Gene),
multiple =F,
width = 800,
selected = "Igfbp7"
))
),
fluidRow(
column(8,offset = 3,
actionButton(inputId = "plot1", label = "FPKM",width=80),
actionButton(inputId = "plot2", label = "LogFc",width=80),
actionButton(inputId = "all",label = "FPKM&LogFc",width=120)
)
),
fluidRow(
column(3)
),
fluidRow(
column(3)
),
fluidRow(
column(12,align="center",
uiOutput("plots")
)
)
)
server <- function(input, output,session) {
observeEvent(input$selectGeneSymbol, {
if(sum(unique(data_mean_sd2$Gene) %in% input$selectGeneSymbol)>0) {
shinyjs::enable("plot2")
shinyjs::enable("all")
}else{
shinyjs::disable("plot2")
shinyjs::disable("all")
}
})
plot_data1 <- eventReactive(list(input$plot1,input$all), {
subset(data_mean_sd, Gene %in% input$selectGeneSymbol)
})
plot_data2 <- eventReactive(list(input$plot2,input$all), {
subset(data_mean_sd2, Gene %in% input$selectGeneSymbol)
})
global <- reactiveValues()
observeEvent(list(input$plot1,input$all), {
req(plot_data1())
#p1 <- eventReactive(list(input$plot1,
# input$all), {
global$p1 <- ggplot(data = plot_data1(), aes(x = Name, y = mean,fill=Name)) +
geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = .2, position = position_dodge(0.9)) +
theme_classic2() +
rotate_x_text(angle = 45) +
theme(legend.position = "none") +
labs(title = input$selectGeneSymbol, x = NULL, y = "FPKM_value") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(plot.margin = unit(c(20, 5, 1, 5), "mm"))+
theme(axis.text.x=element_text(vjust=1,size=12))
})
observeEvent(list(input$plot2,input$all), {
req(plot_data2())
#p2 <- eventReactive(list(input$plot2,
# input$all), {
global$p2 <- ggplot(data = plot_data2(), aes(x = Name, y = mean,fill=Name)) +
geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = .2, position = position_dodge(0.9)) +
theme_classic2() +
rotate_x_text(angle = 45) +
theme(legend.position = "none") +
labs(title = input$selectGeneSymbol, x = NULL, y = "FPKM_value") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(plot.margin = unit(c(20, 5, 1, 5), "mm"))+
theme(axis.text.x=element_text(vjust=1,size=12))
})
output$plt1 <- renderPlot({ global$p1 })
output$plt2 <- renderPlot({ global$p2 })
output$plt3 <- renderPlot({ grid.arrange(global$p1,global$p2, ncol=1) })
observeEvent(input$plot1, {
global$out <- plotOutput("plt1", height=600)
})
observeEvent(input$plot2, {
global$out <- plotOutput("plt2", height=600)
})
observeEvent(input$all, {
global$out <- plotOutput("plt3", height=800)
})
output$plots <- renderUI({
global$out
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
推荐阅读
- .net - 如何读取 OAuthAuthorizationServerProvider 中生成的 refresh_token
- asp.net-core - Dapper 兼容性 .Net Core 3.1
- python - 试图将两个链表添加在一起但得到一个 AttributeError
- amazon-web-services - 为什么我在使用 Ansible playbook 创建 EC2 实例时收到“当前不支持请求的配置”?
- java - 什么控制 WebLogic 中的时区到 GMT 偏移映射?
- android - 可以将使用 Android Studio 制作的应用发布到 iOS 平台吗?
- c# - 如何从 WPF c# 中的 ListBox 中的 TextBox 获取所有值?
- java - 空对象引用上的 Model.Result.getFormatted_address()'
- xamarin - 将组件添加到每个视图
- python - 如何解决 ImportError: dlopen(): Symbol not found:.... Expected in: flat namespace