Re: Best way to format shiny out put

98 views
Skip to first unread message

Joe Cheng

unread,
Apr 27, 2015, 2:00:07 PM4/27/15
to Glenn Schultz, shiny-...@googlegroups.com
You could build a data frame with rownames c("Yield", "Avg. Life", ...) and the columns being the different CPRs, and use dataTableOutput/renderDataTable (or the DT package) to output.

On Sun, Apr 26, 2015 at 11:24 AM, Glenn Schultz <glennm...@gmail.com> wrote:
All,

I know have my shiny app working at least I have an idea to lay out the app and pass information around.  So, below is the code to shiny.   Everything in the nominal example seems to be working okay.  BondLab can be installed from my github site if you want to run the app.  My question is as follows.  Before moving on to graphics some tabular output is required.  For example, MBS.data is a S4 object containing slots with cusip information while PassThrough.1 is a S4 class of analytic results.  The reactive part is worked-out (thanks Joe) . In the  Bond Details tab (it is reactive) I would like to have a table or something like

Bond Name:     bondlabMBS4
Cusip          :     xxxxxx
First Pmt Date: mm/dd/yyyy
Last Pmt Date:  mm/dd/yyyy
... some other stuff

In the yield table tab I would like to do the following (the yield table is reactive).  Any suggestions, this is my first day on shiny and I have not seen any examples I can follow doing what I would like.  Is this an exercise in java and html or can I accomplish this with the current widgets and shiny capabilities.

                                      CPR1                 CPR2
Yield                                xx.xx               xx.xx
Avg. Life
Duration
Mod. Duration
First Pmt Date
Last Pmt Date
Spread to curve
Z-V spread


library(BondLab)


  shinyServer(function(input,output){
  MBS.Data <- reactive({MBS(mbs.id = input$bond.id)
                                   
  })

  })


  shinyServer(function(input, output) {
  


  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)
  })
  output$text1 <- renderText({PassThrough.1()@YieldToMaturity * 100})
  output$text2 <- renderText({PassThrough.1()@WAL})
  })

shinyUI(fluidPage(
  titlePanel("Bond Lab Mortgage Analytics"),
  
  sidebarLayout(
    sidebarPanel(
      helpText("Mortgage Analytics"),
      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" )

      ),
    mainPanel(
    tabsetPanel(
      tabPanel("Bond Details"
               
               ),
      tabPanel("Yield Table", 
               fluidRow(column(1, numericInput("CPR1", label = "CPR", value = 6, min = 0, max = 100),
                               textOutput("text1"),
                               textOutput("text2")),
                        column(1, offset = 2, numericInput("CPR2", label = "CPR", value = 0, min = 0 , max = 100)),
                        column(1, offset = 2, numericInput("CPR3", label = "CPR", value = 0, min = 0,  max = 100))
               )),
      tabPanel("Scenario Return Analysis"),
      tabPanel("Option Adjusted Spread Analysis"),
      tabPanel("Prepayment Analysis")
    )
    )
  )
))

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/5d3921ee-ec49-4ca3-8f96-6ac9601cf4d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Glenn Schultz

unread,
May 1, 2015, 4:09:38 PM5/1/15
to shiny-...@googlegroups.com, glennm...@gmail.com
Hi Joe, thanks I am working on the solution as you suggested.  One question the reactive input widget would be above each column in the datatable - at least that is what I think.  Ideally, the user can change any one of the CPR inputs. So, should I be working with one datatable or would it better to have say six datatables side by side so each are independent?

Glenn

Joe Cheng

unread,
May 1, 2015, 4:27:41 PM5/1/15
to Glenn Schultz, shiny-...@googlegroups.com
Well I don't think you want six tables side by side--their rows might not be lined up if there's a possibility of any of the cells wrapping.

Glenn Schultz

unread,
May 3, 2015, 8:50:52 AM5/3/15
to shiny-...@googlegroups.com, glennm...@gmail.com
Yes, the tables do wrap so independent tables are a no go.  I am looking into the datatable now but not sure how I would organize the input widgets
Reply all
Reply to author
Forward
0 new messages