Integration of Server function with UI

Dear, I am trying to develop a shiny app of DotPlot for similarity analysis of two sequences using the seqinr library built-in function dotPlot() function. The following is my code

library(seqinr)
library(shiny)
# User interface
ui <- fluidPage(
  titlePanel("Welcome to DotMatcher Plot App"),
  sidebarLayout(
    sidebarPanel (
      fileInput("protein1",
        multiple = FALSE,
        accept =c("text", "fasta")),
      fileInput( "protein2",
        multiple=FALSE,
        accept =c("text", "fasta")),
      # Outputs
      mainPanel(
        plotOutput(outputId = "plot")
    )
  )
)
# Server Function
server<- function(input, output) {
  output$plot <- renderPlot({
    dotPlot(s2c(paste(protein1, collapse = ""),s2c(paste(protein2)))
  })
 
}
# App 
shinyApp(ui = ui, server = server)

I am getting following error messages

Error: unexpected '}' in:
"    dotPlot(s2c(paste(protein1, collapse = ""),s2c(paste(protein2)))
  }"
>  
> }
Error: unexpected '}' in "}"
> 
> 
> shinyApp(ui = ui, server = server)
Error in shinyApp(ui = ui, server = server) : object 'server' not found

I will great acknowledge your help.

Hi, your code has a typo. there is a parenthesis missing in the first call to s2c . i've added it in this snippet

server<- function(input, output) {
  output$plot <- renderPlot({
    dotPlot(s2c(paste(protein1, collapse = "")),s2c(paste(protein2)))
  })
    
}
1 Like

Dear Adamgruer Thanks for your help, now i am getting following error

Error in output$plot <- renderPlot({ : object 'output' not found

my apologize for my silly mistakes, i am quite new in programming.

that's okay we all make typos, and it can be really hard to see them sometimes. You provided a good reproducible example so that's great. I don't have the files to input but i've got the app to start up. Some of the fixes

  • There were a couple of missing parentheses in the ui step.
  • the fileInput function requires a label argument, this can be NULL - it is a shame that there is no default provided by shiny
  • in the server function whenever getting values from the app - you need to write input$id_of_input_element

Hope this works for you. I got the app to start up. An error shows up but i assume/hope it will go aways onnce files are selected.

library(seqinr)
library(shiny)
# User interface
ui <- fluidPage(
  titlePanel("Welcome to DotMatcher Plot App"),
  sidebarLayout(
    sidebarPanel (
      fileInput("protein1",
                label = "Choose a file",
                multiple = FALSE,
                accept =c("text", "fasta")),
      fileInput( "protein2",
                 label = NULL,
                 multiple=FALSE,
                 accept =c("text", "fasta"))
      ),
      # Outputs
      mainPanel(
        plotOutput(outputId = "plot")
      )
    )
  )
)
  # Server Function
  server <- function(input, output) {
    output$plot <- renderPlot({
      dotPlot(s2c(paste(input$protein1, collapse = "")),s2c(paste(input$protein2)))
    })
      
  }
  # App 
  shinyApp(ui = ui, server = server)
  
1 Like

Thanks dear, it is now working. As i am new so i hope that through this community i will get lot of help in my bioinformatics projects.

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.