Birkaç gün önce aşağıdaki soruları yanıtladım, R Shiny Dynamic Input, ve soruya verilen cevap doğru olmasına rağmen, şimdi verilen kodu düzeltemediğim için biraz daha detaylandırmak istiyorum. yeni soruma cevap ver. Bu yüzden aslen kullanıcıdan, bir kullanıcı için bir sayı belirtmesini istemek istedim, k demek ki, dinamik olarak kullanıcı için doldurması gereken k alanlarını üretecek. Şimdi, verilen kod, çıktının bir sayısal olduğunu varsayar, ancak kullanıcının, 1, ..., k alanlarının her birinde 5 değerden oluşan bir vektör belirleyebilmesini istiyorum. K belirtildikten sonra, girdiler sayısal değerlerin 5 uzunluğundaki k vektörleri olacak, bu değerleri bir k matrisinde saklayabilmek istiyorum. Bu şekilde daha sonra veri manipülasyonlarını yürütmek için bu değerleri kullanabilirim. Eğer yardımı olacaksa, burada orijinal cevabını kodudur:R Shiny
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
numericInput("numInputs", "How many inputs do you want", 4),
# place to hold dynamic inputs
uiOutput("inputGroup")
),
# this is just a demo to show the input values
mainPanel(textOutput("inputValues"))
)
))
# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {
# observe changes in "numInputs", and create corresponding number of inputs
observeEvent(input$numInputs, {
output$inputGroup = renderUI({
input_list <- lapply(1:input$numInputs, function(i) {
# for each dynamically generated input, give a different name
inputName <- paste("input", i, sep = "")
numericInput(inputName, inputName, 1)
})
do.call(tagList, input_list)
})
})
# this is just a demo to display all the input values
output$inputValues <- renderText({
paste(lapply(1:input$numInputs, function(i) {
inputName <- paste("input", i, sep = "")
input[[inputName]]
}))
})
})
# Run the application
shinyApp(ui = ui, server = server)
Düzenleme İşte
hala yok kod güncellenir tamamen çalışır:library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
numericInput("numInputs", "How many inputs do you want", 4),
# place to hold dynamic inputs
uiOutput("inputGroup")
),
# this is just a demo to show the input values
mainPanel(tableOutput("inputValues"))
)
))
# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {
# observe changes in "numInputs", and create corresponding number of inputs
observeEvent(input$numInputs, {
output$inputValues <- renderTable({
all <- paste(lapply(1:input$numInputs, function(i) {
inputName <- paste("input", i, sep = "")
input[[inputName]]
}))
matrix <- as.matrix(all, ncol=5)
as.data.frame(matrix)
})
})
# this is just a demo to display all the input values
output$inputValues <- renderText({
paste(lapply(1:input$numInputs, function(i) {
inputName <- paste("input", i, sep = "")
input[[inputName]]
}))
})
})
# Run the application
shinyApp(ui = ui, server = server)
teşekkürler. Ancak, kodu çalıştırdığımda, herhangi bir alanı dinamik olarak doldurmaz. – RustyStatistician
Soruyu bu kodu kullanarak güncelledim. – RustyStatistician
Tüm çalışma kodu ile güncellendi. –