'"Subscript out of bounds": Shiny renderPlot() with for loop to generate plots
I'm trying to use a for loop to create scatter plots. list_grps represents a number of groups which contain data (i.e. each group in the list contains some number of columns from a dataframe). I'm then applying a function to create scatterplots over these lists and saving the output to a list (list_scatter_plots). When I try to renderPlot() for my plots, I get the message "subscript out of bounds". The trace from shiny has the following additional details:
SEND {"errors":{"scatter":{"message":"subscript out of bounds","call":"grobs[[i]]","type":null}},"values":{},"inputMessages":[]}
Sample dataset: https://docs.google.com/spreadsheets/d/1j63zpOKBFFtuNTWga3Da7ytUnBfwGRVucGIFUENVsQQ/edit?usp=sharing
This is the code:
library(shiny) library(rio) library(DT) library(tidyverse) library(ggpubr)
ui <- navbarPage("App Name",
tabPanel("File Upload",
sidebarLayout(
sidebarPanel(
tags$h1(tags$b("File Upload")),
fileInput("file1",
"Choose File",
multiple = FALSE,
accept = c("text/csv",
"text/tab-separated-values",
".csv",
"text/tsv",
"text/comma-separated-values",
".tsv")),
placeholder = "No file selected",
tags$hr(),
selectInput("dftype", label = "Data Type",
choices = c(Phosphoproteome = "pProt",
Proteome = "Prot"),
selected = "Prot"),
tags$hr(),
tags$h1(tags$b("Select Groups")),
tags$p("Select columns on table, then press 'Create new biological group' to group selected samples."),
actionButton("cr_grp", "Create new biological group")
),
mainPanel(
DT::dataTableOutput(outputId = "exp_df")
)
)),
tabPanel("Quality Control"
sidebarPanel(
),
mainPanel(
plotOutput(outputId = "scatter")
)
))
server <- function(input, output, session) {
exp_dff <- eventReactive(input$file1,{
infile <- input$file1
req(infile)
return(select(import(infile$datapath), -starts_with(c("Boost", "Empty", "MaxPepProb", "ReferenceIntensity"))))
})
output$exp_df <- DT::renderDataTable(exp_dff())
list_grps <- list()
observeEvent(input$cr_grp, {
append(list_grps, input$exp_df_columns_selected)
})
list_scatter_plots <- lapply(list_grps, function(x) pairs(x, pch=20, col=“red”))
output$scatter <- renderPlot(ggarrange(plotlist = list_scatter_plots))
}
shinyApp(ui=ui, server=server)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
