incompatible types (from closure to double) in subassignment type fix

1,089 views
Skip to first unread message

Fizar Ahmed

unread,
Mar 20, 2016, 5:11:47 PM3/20/16
to Shiny - Web Framework for R
Would you please help me to find the reason of this error:

Error in Am[1] = renderPrint(input$num) : 
  incompatible types (from closure to double) in subassignment type fix

My ui.r:

shinyUI(fluidPage(
  titlePanel("Matching future job requirements with educational portfolio"), 
  
  sidebarLayout(
    sidebarPanel(  
       numericInput("num", label = h3("Numeric input"), value = 1),
   submitButton("Update View")),
      mainPanel(
        tabsetPanel(
          tabPanel("Input Coefficient",      
               tags$div(class = "header", checked = NA,
                          tags$p(h1("Input Coefficent for 19 industries")),
                          tableOutput("input_coefficient")
                 ),
        tabPanel("Import Coefficient",tableOutput("import_coefficient")),
                  )
              )) 
         ))


server.R

shinyServer(function(input, output){
  
Am<-as.matrix(read.csv("data/input_coefficient.csv", header=F, sep=","))
Am[1]=renderPrint(input$num)
output$input_coefficient <- renderTable({Am})
})

My target to change the first value of this Am Matrix

sai

unread,
Mar 20, 2016, 11:57:37 PM3/20/16
to Shiny - Web Framework for R
Hi, 

I'm not clear on what you are trying to achieve with this line ' Am[1] = renderPrint(input$num) ' .
renderPrint() is a function used to generate the required HTML output to show it on the webpage.

If you are trying to change the first cell in the matrix then you can try the below code in server.R. 
Also, data read and manipulations can only be done in a reactive components inside shinyServer function. 
go through this tutorial on reactivity to understand it better.


server.R

shinyServer(function(input, output){
  
 Am <- reactive({
   Am<-as.matrix(read.csv("train.csv", header=F, sep=","))
   Am[1,1]<- as.numeric(input$num)
   return(Am)
 })

  output$input_coefficient <- renderTable({Am()})
})


Regards,
Sai
Reply all
Reply to author
Forward
0 new messages