I am trying to build an app in Shiny that (1) asks user for number of Assets in his/her portfolio. Depending on the numeric entry, (2) the user is presented with one numeric box to enter the % of portfolio owned AND one box for Ticker/name of the Asset. For instance, If the user enters 3 for number of assets in portfolio, he will be presented with something like this:
Asset1 ----> Enter ticker______ Enter Wight______
Asset2 ----> Enter ticker______ Enter Wight______
Asset3 ----> Enter ticker______ Enter Wight______
I have figured out the programing till this point. Now the next step that I want is for user to enter all Asset Tickers and Weights, and press submit. At this point, the user will be shown a table with each asset ticker and weight entered, along with other information such as Covariance, beta, volatility of portfolio that I will calculate my self.
The issue that I am having is how to build a data frame or rather a record of all inputs when the number of inputs can vary i.e. dynamic and depend on the number of assets user owns/enters. As such, I am completely lost.
Below is my code. Any help will be greatly appreciated as I have been stuck on this for a while now.
SERVER.R
library(shiny)
shinyServer( function(input, output, session) {
output$tickers <- renderUI({
numAssets <- as.integer(input$assets)
lapply(1:numAssets, function(i) {
list(tags$p(tags$u(h4(paste0("Asset ", i)))),
textInput(paste("ticker", i), label = "Ticker Name", value = "Enter ticker..."),
numericInput(paste("weight", i), label = "Weight of Asset", value = 0))
})
})
# the following produced table with same number of rows as number of assets entered. However, there is no link to what the user entered for weights and ticker.
# output$table <- renderTable ({
# numAssets <- as.integer(input$assets)
# df=data.frame()
# df <-data.frame (paste0("ticker",1:numAssets), paste0("weight",1:numAssets))
# })
})
--
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/6d6faa80-2c80-4030-a0f1-183be75f9a19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.