[英]Add or delete rows of textInput
I'm looking for ways to add / delete rows of textInput
in R Shiny.我正在寻找在 R Shiny 中添加/删除
textInput
行的方法。 The desired output is similar to the image below:所需的输出类似于下图:
Image credits: https://www.tutorialrepublic.com/snippets/preview.php?topic=bootstrap&file=table-with-add-and-delete-row-feature图片来源: https : //www.tutorialrepublic.com/snippets/preview.php?topic=bootstrap&file=table-with-add-and-delete-row-feature
The desired output is not necessarily a table.所需的输出不一定是表格。 Alternatively, when the user clicks "Add" a list containing same number of blank
textInput
entries as the previous row (user cannot add more columns) should appear.或者,当用户单击“添加”时,应出现一个包含与前一行相同数量的空白
textInput
条目的列表(用户不能添加更多列)。 When the user clicks "Delete", the corresponding row should be removed.当用户点击“删除”时,相应的行应该被删除。 It is important to be able to capture the user input from each text box .
能够从每个文本框中捕获用户输入非常重要。 Is there a way to accomplish this easily using R Shiny?
有没有办法使用 R Shiny 轻松完成此操作?
How about this:这个怎么样:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("input_no",
"Number of inputs:",
min = 1,
max = 5,
value = 30),
uiOutput("dateinputs")
),
mainPanel(
verbatimTextOutput("res")
)
)
)
server <- function(input, output) {
output$dateinputs <- renderUI({
no <- as.integer(input$input_no)
lapply(1:no, function(i) {
textInput(paste0("ind", i),
label = paste("Textinput ", i))
})
})
report_dates <- reactive({
no <- as.integer(input$input_no)
sapply(1:no, function(i) {
input[[paste0("ind", i)]]
})
})
output$res <- renderPrint({
report_dates()
})
}
shinyApp(ui = ui, server = server)
Another option is to use the edit function of DT:另一种选择是使用DT的编辑功能:
Have a look at this example: https://rstudio.github.io/DT/shiny.html (Section 2.4).看看这个例子: https : //rstudio.github.io/DT/shiny.html (第 2.4 节)。 You could create an actionButton() to add rows and edit them in the table
您可以创建一个 actionButton() 来添加行并在表中编辑它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.