第一个部门的输出“总计”应显示“ Product11”和“ Product12”的输入总和。
第二部分的输出“总计”是“ Product21”和“ Product22”的输入之和。依此类推...
我尝试了很多,但没有任何效果。你们中的任何一个人不知道该怎么做吗?
所需的输出:
library(shiny)
library(shinydashboard)
# Define UI
ui <- fluidPage(
titlePanel("Identify Total amount/Divison"),
sidebarLayout(
sidebarPanel(
width = 12,
# Buttons to add/remove a division
actionButton("add", "Add Divison"),
actionButton("remove", "Remove Divison"),
div(id = "questions",
style = "border: 1px solid silver;")
),
mainPanel(
)))
# Define server logic
server <- function(input, output) {
values <- reactiveValues(num_questions = 0)
# Add a division
observeEvent(input$add, ignoreNULL = FALSE, ignoreInit = TRUE,{
values$num_questions <- values$num_questions + 1
num <- values$num_questions
#ui = tags$div(
# observe({
insertUI(immediate = TRUE,
selector = "#questions", where = "beforeEnd",
splitLayout(
cellWidths = c("39%","30%", "40%"),
cellArgs = list(style = "padding: 3px"),
id = paste0("question", num),
selectizeInput(inputId =paste0("Number_Product1_", num),
label = paste0("Product1", num), isolate(seq(from = 0, to = 100000, by = 10)), multiple=FALSE),
selectizeInput(inputId =paste0("Number_Product2_", num),
label = paste0("Product2", num), isolate(seq(from = 0, to = 100000, by = 10)), multiple=FALSE),
box(
title = "Total", width = 12, background = "black",
print(input$Number_Product1_1),
textOutput("total1")
)
))
#)
# })
})
#observe({
# require(input$Number_Product1_1)
output$total1 <- renderText({
numtxt <- c(input[["Number_Product1_1"]])
if (values$num_questions > 0) {
for (i in 1:values$num_questions) {
numtxt <- c(numtxt, input[[paste0("Number_Product1_", i + 1)]])
}
numtxt
}
})
# })
output$total2 <- renderText({
numtxt2 <- c(input[["Number_Product2_1"]])
if (values$num_questions > 0) {
for (i in 1:values$num_questions) {
numtxt2 <- c(numtxt2, input[[paste0("Number_Product2_", i + 1)]])
}
numtxt2
}
#output$total <- renderText({out_rows()})
# Remove a division
observeEvent(input$remove, {
num <- values$num_questions
# Don't let the user remove the very first Row
if (num == 1) {
return()
}
removeUI(selector = paste0("#question", num))
values$num_questions <- values$num_questions - 1
})
}
# Run the application
shinyApp(ui = ui, server = server)