How to use dynamic parametes in shinydashboard


#1

Hello,
I have a problem with dynamic parameters. Fristly, I want to input the first paramers, say m. This value are chosen by users. From this value, I want to input m other paremeters, say n1, n2,…,nm and then use these value in my calculation.
For example, with m=3, I have to make another box with 3 places to input n1,n2,n3
with m=4, I have to make another box with 4 places to input n1,n2,n3, n4
and use these values in other function. In my code here, I cannot make it dynamic.
Could you please help me?
Thank you very much.
ui <- dashboardPage(
dashboardHeader(title =“My Shiny”),
dashboardSidebar(
sidebarMenu( menuItem(“Home”, tabName=“home”, icon = icon(“fa fa-hand-o-right”) ))
),
dashboardBody(
tabItems(
tabItem(tabName = “home”,
fluidRow( box( title = “The first parameter”, status = “primary”, solidHeader = TRUE, width = 4,
numericInput(“num1”, label = h5(“m”), value = 4,min=1,step=1)),
box(title = "The second parameters ", status = “primary”, solidHeader = TRUE, width = 4,
numericInput(“num2”, label = h5(“n1”), value =1),
numericInput(“num3”, label = h5(“n2”), value = 0.08),
numericInput(“num4”, label = h5(“n3”), value = 0.1),
numericInput(“num5”, label = h5(“n4”), value = 0.05 )
),
box(title = “Resluts”, status = “primary”, solidHeader = TRUE, width = 3,
tableOutput(“result”))
))
))
)
server <- function(input, output) {
table<- reactive({ n2<- input$num2
n3<- input$num3
n4<- input$num4
n5<- input$num5
a1<- n5+n2+n3+n4
a2<-n3-n2-n5
table1<-data.frame(a1,a2)
colnames(table1)=c(“result1”, “result2”)
table1
})
result1=reactive({ result=table()
result
})
output$result=renderTable({ if(is.null(result1())){return(NULL)}
result1() },
include.rownames=TRUE )
}

shinyApp(ui, server)


#2

check ?uiOutput and ?renderUI and related articles.

https://shiny.rstudio.com/articles/dynamic-ui.html