0

So I wrote an R Shiny app that analyzes student loan information and recommends the best way to pay them down. A lot of people, including myself, have multiple student loans with different interest rates, so I made some conditionalPanels that show up based on how many student loans the user says they have. Each conditionalPanel has numericInputs for loan principal, interest rate, and how much the user wants to pay per month. It's a bit of a process for the user to enter all this data once, and unfortunately it all gets wiped out if the user navigates away from the page or refreshes it.

How can I save the session data so the user doesn't have to re-enter their information in numericInputs every single time? I feel like the answer has something to do with accessing session data, but I'm not really sure. Any help is appreciated. Thanks!

Here's an example of what goes on, on the UI side:

# Define UI for application
ui <- shinyUI(fluidPage(

# Application title
titlePanel("Student Loan Calculator"),

# Sidebar with nested sidebar panels containing numeric inputs to enter info about each loan.
sidebarLayout(

    sidebarPanel(width = '3',
             numericInput("numStuLoan",
                          "How many student loans do you have?",
                          min = 0,
                          max = 5,
                          value = 1,
                          step = 1),
             HTML("<br>"),
             #### #### #### #### ####
             #### Loan 1 ## #### ####
             #### #### #### #### ####
             conditionalPanel(condition="input.numStuLoan > 0",
                              HTML("<div align = 'left'><font size = '4'><b>1st Loan</b></font></div>"),
                              numericInput("loanPrin1",
                                           "Principal",
                                           min = 0,
                                           max = Inf,
                                           value = 10000,
                                           step = 50),

                              numericInput("loanInt1",
                                           "Interest Rate",
                                           min = 0.00,
                                           max = 20.00,
                                           value = 5.29,
                                           step = 0.1),

                              numericInput("monthPay1",
                                           "Monthly Payment",
                                           min = 0.00,
                                           max = Inf,
                                           value = 250,
                                           step = 1)),
             HTML("<br>"),
             ...
             ...
             ...
             {this code basically repeats for each loan}
Ashwin
  • 51
  • 1
  • 7
  • 1
    There are several possibilities. First, did you take a look at bookmarking? https://shiny.rstudio.com/gallery/bookmarking-url.html Advantage: You dont have to change your code much. Disadvantage: The user has to keep a link. Second, what i used for that purpose is to save the client data in reactiveValues and reload that if necessary. Advantage: No link needed. Disadvantage: You might have to adjust your code. Third, I build an input logger: http://www.big-data-scientist.de/shiny/rstudio/sample-apps/ShinyInputLog/ where all inputs are saved (without variable amounts of inputs). – Tonio Liebrand Mar 19 '17 at 22:50
  • I'll take a look at bookmarking. Thanks! – Ashwin Mar 20 '17 at 23:31

0 Answers0