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 bo
ui.R
library(shiny)
shinyUI(pageWithSidebar (
headerPanel( "Portfolio Returns"),
sidebarPanel(
numericInput("assets", label = "Enter Number of Assets in Portfolio", value="1"),
uiOutput("tickers")
),
mainPanel()
))
server.R
-Note that to pass multiple items in the renderUI()
function you have to group them into a list, and here lapply()
is creating a list of lists.
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(paste0("ticker", i), label = "Ticker Name", value = "Enter ticker..."),
numericInput(paste0("weight", i), label = "Weight of Asset", value=0))
})
})
})