Using DT with S4 classes

61 views
Skip to first unread message

Glenn Schultz

unread,
May 3, 2015, 12:16:02 PM5/3/15
to shiny-...@googlegroups.com
All, I have an S4 class which consists of both descriptive information that are also the input values for other functions.  I would like to create an Shiny page that lists the descriptive information for example the S4 class looks is a follows:


...@Cusip
...@ID
...@Coupon
...@Term
...@ (a bunch of other stuff)

I would like the shiny page to show under the navbar Bond Details to show as follows:

Cusip: ...@Cusip
ID     : ...@ ID

and so on.  Is data table the correct way to go about rendering information in a S4 class?

Best Regards,
Glenn 

Yihui Xie

unread,
May 3, 2015, 12:20:29 PM5/3/15
to Glenn Schultz, shiny-discuss
Sorry, but I don't quite understand your question. DT is supposed to
display a data frame or matrix, and what is the data frame or matrix
in your case?

Regards,
Yihui

Glenn Schultz

unread,
May 3, 2015, 2:34:57 PM5/3/15
to shiny-...@googlegroups.com
I would like to be able to present both the S4 slot names and their associated values.  So, I am thinking that I need to get those into a data frame and then use DT to present them in shiny.  This is a case where the user would like to "see" the inputs and bond data as well as "see" and "visualize" the results.  So, my thought is to extract the slot names as follows :

names <- data.frame(slotNames(MBS.Data), stringsAsFactors = FALSE)
values <- (note:I have no idea how to get the vector of slot values)
BondData <- data.frame(cbind(names, values)
output$BondData <- renderTable(BondData)

Glenn Schultz

unread,
May 3, 2015, 3:16:41 PM5/3/15
to shiny-...@googlegroups.com

Here is a screen shot I would like,  the cusip value should be to the right of the label "Cusip :".  After research all afternoon it seems I will have to access the value of each slot of the class MBSDetails individually.  So, I would consider today a victory if all I could do is something as simple as 

Bond ID: bondlabMBS4

Cusip : 23456  

Here is the shiny code

server.R

library(BondLab)

library(DT)




  shinyServer(function(input, output) {

  

  MBS.Data <- reactive({MBS(MBS.id = input$bond.id)})

                       


  PassThrough.1 <- reactive({PassThroughAnalytics(bond.id = input$bond.id,

                                                  original.bal = input$OrigFace,

                                                  price = 105,

                                                  trade.date = "01-10-2013",

                                                  settlement.date = "01-13-2013",

                                                  scenario.set = "NC",

                                                  PrepaymentAssumption = "CPR",

                                                  CPR = input$CPR1)

  })

  

  PassThrough.2 <- reactive({PassThroughAnalytics(bond.id = input$bond.id,

                                                  original.bal = input$OrigFace,

                                                  price = 105,

                                                  trade.date = "01-10-2013",

                                                  settlement.date = "01-13-2013",

                                                  scenario.set = "NC",

                                                  PrepaymentAssumption = "CPR",

                                                  CPR = input$CPR2)

  })                           

  

 output$Cusip <- renderText("Cusip :")

 output$CusipValue <- renderText({MBS.Data()@Cusip})

  

  

  output$des <- renderText({MBS.Data()@ID})

  output$cusip <- renderText({MBS.Data()@Cusip})

  output$coupon <- renderText({MBS.Data()@Coupon})

  output$gwac <- renderText({MBS.Data()@GWac})

  


  })


 ui.R

shinyUI(fluidPage(

  titlePanel("Bond Lab Mortgage Analytics"),

  

  sidebarLayout(

    sidebarPanel(

      helpText("Bond Data Inputs"),

      textInput("bond.id",

                label = "Cusip"),

      numericInput("OrigFace",

                   label = "Original Face",

                   value = NULL,

                   min = 1000,

                   max = 1000000),

      numericInput("Price",

                label = "Price",

                value = 100,

                min = 0,

                max = 200,

                step = 1/128),

      dateInput("Trade.Date",

                label = "Trade Date"),

      dateInput("Settlement.Date",

                label = "Settlement Date" ),

      width = 2


      ),

    mainPanel(

    navbarPage(

      title = 'Analytics',

      tabPanel('Bond Details', 

              textOutput("Cusip"),

              textOutput("cusip")),

      tabPanel('Yield Table'),

      tabPanel('Scenario Analysis'),

      tabPanel('OAS Analysis')

)

  )

    )

      ))




On Sunday, May 3, 2015 at 11:16:02 AM UTC-5, Glenn Schultz wrote:

adrie...@hotmail.com

unread,
May 4, 2015, 5:02:43 AM5/4/15
to shiny-...@googlegroups.com
Hello,
I don't get to launch your app,
here are the messages :

Error in library(BondLab) : there is no package called BondLab

> install.packages("BondLab")
Installing package into ‘/home/bessy/R/x86_64-pc-linux-gnu-library/3.1
(as lib is unspecified)
Warning in install.packages :
 
package BondLab is not available (for R version 3.1.1)



Glenn Schultz

unread,
May 4, 2015, 12:58:49 PM5/4/15
to shiny-...@googlegroups.com
BondLab is on github.  You will have to use devtools to install bondlab

adrie...@hotmail.com

unread,
May 5, 2015, 4:34:12 AM5/5/15
to shiny-...@googlegroups.com
I displays this :

> devtools::install_github("rstudio/BondLab")
Downloading github repo rstudio/BondLab@master
Erreur dans download(dest, src, auth) : client error: (404) Not Found


adrie...@hotmail.com

unread,
May 5, 2015, 4:42:06 AM5/5/15
to shiny-...@googlegroups.com
I'm sorry I didn't write the right source :
> devtools::install_github("glennmschultz/BondLab")
works but it displays :

ERROR: dependency termstrc is not available for package BondLab
* removing ‘/home/bessy/R/x86_64-pc-linux-gnu-library/3.1/BondLab
Erreur : Command failed (1)
De plus : Messages d'avis :
1: In utils::install.packages(deps, dependencies = NA, Ncpus = threads) :
  installation of package ‘rgl’ had non-zero exit status
2: In utils::install.packages(deps, dependencies = NA, Ncpus = threads) :
  installation of package ‘termstrc’ had non-zero exit status




Reply all
Reply to author
Forward
0 new messages