'closure' is not subsettable error in r shiny
1
0
Entering edit mode
19 months ago
Sude • 0
library(shiny)
library(tidyverse)
library(ISLR)
library(glmnet)
library(dplyr)
library(tidyr)
metadata <- readRDS("merging2.rds")
ui <- fluidPage( titlePanel("BLCA-GENE EXPRESSION"),

                 sidebarPanel(
                   selectInput(
                     inputId = "gene",
                     label = "Please choose a gene",
                     choices = c(
                       "ENSG00000000003.15"="ENSG00000000003.15",
                       "ENSG00000000005.6"="ENSG00000000005.6",
                       "ENSG00000000419.13"="ENSG00000000419.13",
                       "ENSG00000000457.14"="ENSG00000000457.14",
                       "ENSG00000000460.17"="ENSG00000000460.17",
                       "ENSG00000000938.13"="ENSG00000000938.13",
                       "ENSG00000000971.16"="ENSG00000000971.16",
                       "ENSG00000001036.14"="ENSG00000001036.14",
                       "ENSG00000001084.13"="ENSG00000001084.13",
                       "ENSG00000001167.14"="ENSG00000001167.14",
                       "ENSG00000001460.18"="ENSG00000001460.18",
                       "ENSG00000001461.17"="ENSG00000001461.17",
                       "ENSG00000001497.18"="ENSG00000001497.18",
                       "ENSG00000001561.7"="ENSG00000001561.7",
                       "ENSG00000001617.12"="ENSG00000001617.12",
                       "ENSG00000001626.16"="ENSG00000001626.16",
                       "ENSG00000001629.10"="ENSG00000001629.10",
                       "ENSG00000001630.17"="ENSG00000001630.17",
                       "ENSG00000001631.16"="ENSG00000001631.16",
                       "ENSG00000002016.18"="ENSG00000002016.18",
                       "ENSG00000002079.14"="ENSG00000002079.14",
                       "ENSG00000002330.14"="ENSG00000002330.14",
                       "ENSG00000002549.12"="ENSG00000002549.12",
                       "ENSG00000002586.20"="ENSG00000002586.20",
                       "ENSG00000002586.20_PAR_Y"="ENSG00000002586.20_PAR_Y",
                       "ENSG00000002587.10"="ENSG00000002587.10",
                       "ENSG00000002726.21"="ENSG00000002726.21",
                       "ENSG00000002745.13"="ENSG00000002745.13",
                       "ENSG00000002746.15"="ENSG00000002746.15",
                       "ENSG00000002822.15"="ENSG00000002822.15",
                       "ENSG00000002834.18"="ENSG00000002834.18",
                       "ENSG00000002919.15"= "ENSG00000002919.15",
                       "ENSG00000002933.9"="ENSG00000002933.9",
                       "ENSG00000003056.8"="ENSG00000003056.8",
                       "ENSG00000003096.14"="ENSG00000003096.14",
                       "ENSG00000003137.8"= "ENSG00000003137.8",
                       "ENSG00000003147.19"="ENSG00000003147.19",
                       "ENSG00000003249.15"="ENSG00000003249.15",
                       "ENSG00000003393.15"= "ENSG00000003393.15",
                       "ENSG00000003400.15"="ENSG00000003400.15",
                       "ENSG00000003402.20"="ENSG00000003402.20",
                       "ENSG00000003436.16"= "ENSG00000003436.16",
                       "ENSG00000003509.16"="ENSG00000003509.16",
                       "ENSG00000003756.17"="ENSG00000003756.17",
                       "ENSG00000003987.14"="ENSG00000003987.14",
                       "ENSG00000003989.18"="ENSG00000003989.18",
                       "ENSG00000004059.11"= "ENSG00000004059.11",
                       "ENSG00000004139.14"="ENSG00000004139.14",
                       "ENSG00000004142.12"="ENSG00000004142.12" ),
                     selected = ""),

                   radioButtons(
                     inputId="choices",
                     label = "Please choose one of the below choices",
                     choices = c("lasso"="lasso", 
                                 "ridge"="ridge"),




                     plotOutput(outputId = "hist")
                   )
                 )
)




server <- function(input,output) {

  plotOutput$hist <- renderPlot({




    newx <- data.matrix(metadata[1:20,1:2])
    newy <- metadata$ENSG00000000003.15[1:20]

    library(glmnet)

    #perform k-fold cross-validation to find optimal lambda value
    dataa_shiny == cv.glmnet(newx, newy, alpha = 1)

    #find optimal lambda value that minimizes test MSE
    plot_shiny <- dataa_shiny$lambda.min




    #produce plot of test MSE by lambda value
    plot(dataa_shiny) })}

shinyApp(ui=ui, server=server)

but there is a error like

Error in plotOutput$hist <- renderPlot({ : 
  object of type 'closure' is not subsettable
shiny R • 803 views
ADD COMMENT
3
Entering edit mode
19 months ago
Meisam ▴ 250

Welcome to biostars, since your example is not reproducible it is not possible to help you, but I noticed a couple vital errors in your code: First, in the server you have to address the outputs with the output name prefix that you specify in your server function, so here for your hist object it should be output$hist not plotOutput$hist, it does not mean anything for the app. Second, again in your server side you have a line doing cross validation with cv.glmnet(), instead of assigning the result to the dataa_shiny object (with either <- or =) you logically evaluate it (==) which again does not mean anything for your subsequent code.

Anyways for these kinds of questions you better use programming Q&A forums like stackoverflow rather than biostars since your question is not related to bioinformatics or computational biology.

ADD COMMENT
0
Entering edit mode

Thank you so much...

ADD REPLY

Login before adding your answer.

Traffic: 1995 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6