I want to use two text from by the user in a Shiny apps, and pass that two text values to another function, I don't know what I'm missing because the code doesn't works and returns "input object not found"
I want to use that two inputs to make the contrasts in the makeContrasts() function. That function accept character vectors to make the contrasts
Here is the code
header <- dashboardHeader(
title = "DGE Ebayes Analyzer"
)
sidebar <- dashboardSidebar(
#sidebarmenu
sidebarMenu(id ="tabs",
menuItem("DGE", tabName = "dge", icon = icon("server"))
)
)
body <- dashboardBody(
#tabitems
tabItems(
tabItem(tabName = "dge",
h2("DGE Analysis"),
fluidRow(
box(title = "TARGETS",
solidHeader = T, status = "info", width = 6,
fileInput("file2", "Load custom targets file",
accept = ".csv",
placeholder = "Please, load custom targets file"),
submitButton("Submit")
),
box(title = "Selecting Groups",
solidHeader = T, status = "warning", width = 12,
#code to make group boxes for text input from user
box(title = "Select Groups",
solidHeader = T, status = "info", width = 12,
fluidRow(
column(6,
textInput(inputId = "group1",
label="Group 1",
value = "")
),
column(6,
textInput(inputId = "group2",
label = "Group 2",
value = ""),
submitButton("Submit")
))
)
),
box(title = "Contrasts",
solidHeader = T, status = "info",width = 12,
dataTableOutput("cont"))
)
)
)
)
ui <- dashboardPage(header, sidebar, body, skin = "yellow")
server <- function(input, output){
#####Load targets file#################
targets <- reactive({
validate(
need(input$file2 !="", "Please load the custom targets file")
)
targets1 = input$file2
data1 = read.csv(targets1$datapath,sep = ";")
return(data1)
})
###Design Matrix######
design <- reactive({
groups <- as.character(targets()$Group)
groups1 <- as.factor(groups)
lev <- factor(groups1, levels = unique(groups1))
design <- model.matrix(~ 0 + lev)
colnames(design) <- levels(lev)
rownames(design) <- targets()$Name
return(design)
})
#Make Contrasts
cont.matrix <- reactive({
contrasts <- makeContrasts(
contrasts =paste(input$group1, input$group2, sep="-"),
levels = design())
})
#table contrasts
output$cont <- renderDataTable({
cont.matrix()
})
}
shinyApp(ui = ui, server = server)