Sorry,I really need help from you .
Here is my sample data and code:
The column is Gene sets
**I mean when I input one gene and the click the actionbutton, the barplot will appear but I tried **
several times it doesn't work.
My code here:
library(shiny)
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
mean_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
)
names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
sd_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(runif(1000, 5, 10), nrow = 20)
)
names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
###
ui <- fluidPage(
pageWithSidebar(
headerPanel("123"),
sidebarPanel(
selectInput(
"selectGeneSymbol",
"123:",
choices = colnames(mean_data)[-1],
multiple =F,
width = 400,
selected = 1
),
actionButton(inputId = "plot1", label = "FPKM"),
),
mainPanel(
uiOutput("all")
)
)
)
server <- function(input, output, session) {
plot_data1 <- reactive({
subset(mean_data, colnames(mean_data)[-1] %in% input$selectGeneSymbol)
})
global <- reactiveValues(out = NULL)
observeEvent(input$plot1, {
global$out <- plotOutput("plot1", height=500)
})
output$all <- renderUI({
global$out
})
p1 <- eventReactive(list(input$plot1,
input$all), {
ggplot(data = mean_data, aes(x = mean_data$Name, y = mean_data[,input$selectGeneSymbol],fill=Name)) +
geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
geom_errorbar(aes(ymin = mean_data[,input$selectGeneSymbol] - sd_data[,input$selectGeneSymbol], ymax = mean_data[,input$selectGeneSymbol] + sd_data[,input$selectGeneSymbol]), 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 = "123_value")
})
output$plot1 <- renderPlot({ p1() })
output$plot3 <- renderPlot({ grid.arrange(p1(),p2(), ncol=1) })
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
I combined mean_data and sd_data before and it works well.
Now I use both of them and choose the column of mean_data as the input but the actionbutton doesn't work .The barplot always appear before clicking the button.
I tried several times but I don't know where the code I have to change.
I need your help. And it's urgent. Vary thankful.