I have an app where I would like to add different numbers of UiOutputs based on a number chosen by the user. Right now I am finding myself doing a ton of redundant conditional panels to create the outcome I am looking for. I was wondering if there is an easier way to produce the desired outcome through a function like "switch".
Here is the code using conditional Panels. The outcome is desirable. The amount of conditional panels and repetition is not.
I will only show with 2 conditional Panels but in my app I have 9. The app simply asks the users how many stocks they want to chose in their portfolio and the amount of shares for each stock.
library(shiny)
tickers = c("SPY", "IWM", "QQQ")
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
mainPanel(
h3("lets test the corr Mat"),
#inputs stock
#inputs weight
radioButtons("howMany", "How Many ETF's?", choices = c(1, 2, 3, 4, 5, 6), selected = 1),
actionButton("stest", "Stress Portfolio"),
conditionalPanel("input.howMany == '1'",
selectizeInput("stock1", "choseStock 1", choices = tickers, selected = "SPY"),
numericInput("weight1", "Choose Number of Shares 1", value = 100, min = 0, max = NA, step = 1)),
conditionalPanel("input.howMany == '2'",
selectizeInput("stock1", "choseStock 1", choices = tickers, selected = "SPY"),
selectizeInput("stock2", "choseStock 2", choices = tickers, selected = "QQQ"),
numericInput("weight1", "Choose Number of Shares 1", value = 100, min = 0, max = NA, step = 1),
numericInput("weight2", "Choose Number of Shares 2", value = 100, min = 0, max = NA, step = 1))
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)