我有五個列,每個列都有數字輸入(numericInputs)。我還有一個selectInput,用戶可以從中選擇一個1到5之間的整數。如果用戶從選擇輸入中選擇了n,我希望只顯示前n列。
現在,我只有一個顯示所有5列的靜態版本:
ui <- fluidPage()
fluidRow()
column([col1 stuff]),
...
column([col5 stuff])
))
uj5u.com熱心網友回復:
這個怎么樣
library(shiny)
ui <- fluidPage()
selectizeInput("n_col"。 "Choose col number", choices = 1。 5, selected = 2),
fluidRow()
uiOutput("col_out"/span>)
)
)
服務器 < - function(input, 輸出,會話) {
# define column content
cols <- list()
column()
2,
p("This is col 1"),
numericInput("nu1"/span>。 "nu1", value = 1。 min = 1。 max = 100)
),
列()
2,
p("This is col 2"),
numericInput("nu2"/span>。 "nu2", value = 1。 min = 1。 max = 100)
),
列()
2,
p("這是col 3"),
numericInput("nu3"/span>。 "nu3", value = 1, min = 1。 max = 100)
),
列()
2,
p("這是col 4"),
numericInput("nu4"/span>。 "nu4", value = 1。 min = 1。 max = 100)
),
列()
2,
p("this is col 5"),
numericInput("nu5"/span>。 "nu5", value = 1。 min = 1。 max = 100)
)
)
output$col_out <- renderUI()
cols[1:as. numeric(input$n_col)]
)
}
shinyApp(ui, server)
uj5u.com熱心網友回復:
你可以使用lapply來動態地創建輸入。
library(shiny)
df <- mtcars[/span>1: 5, 1:5]/span>
ui <- fluidPage()
h3('動態輸入選擇'),
selectInput("col", "選擇col number"。 選擇 = seq_along(df))。
br(), br(),
uiOutput("num_input"/span>)
)
server < - function(input,output) {>
output$num_input <- renderUI({
lapply(seq_len(input$col)。 function(x)
numericInput(paste0('inp'。 x), paste0('Input ', x), 1。 1, 10))
})
}
shinyApp(ui, server)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/322177.html
標籤:


