这不是关于使用renderUI创建模块的问题。使用renderUI时,您需要在UI函数中放置一个占位符,然后在服务器函数中编写控件/小部件。
模块分为两个部分。您需要将其中一部分添加到UI函数中,另一部分使用callModule()添加到服务器函数中。
我有一个滑块模块。当单击“添加”操作按钮时,我想将其添加到wellpanel中。如果有帮助,您可以将复制模块想象为每次单击按钮时都会重复多次。复制的模块应该都是独立的。
外观上: 我想知道如何在UI函数中添加模块的UI部分以及在服务器函数中添加服务器部分的操作按钮。
模块分为两个部分。您需要将其中一部分添加到UI函数中,另一部分使用callModule()添加到服务器函数中。
我有一个滑块模块。当单击“添加”操作按钮时,我想将其添加到wellpanel中。如果有帮助,您可以将复制模块想象为每次单击按钮时都会重复多次。复制的模块应该都是独立的。
外观上: 我想知道如何在UI函数中添加模块的UI部分以及在服务器函数中添加服务器部分的操作按钮。
#Dynamically adding modules
library(shiny)
#slider module ------------------------
sliderUI <- function(id) {
ns <- NS(id)
sliderInput(ns("bins"), "Number of Bins:", min = 1, max = 5, value = 3)
}
slider <- function(input, output, session) {}
#shiny app ------------------------
ui <- fixedPage(
fixedRow(
column(width = 4, wellPanel(
h4("Slider Module"),
sliderUI("slider"),
actionButton("addSliderModule", "Add Slider Module"))
),
column(width = 4, wellPanel(
h4("Dynamic Loading Modules"),
p("Clicking on the 'Add' button on the left should add the module here. You should be able to duplicate that slider module as many times as the button is clicked"),
hr())
)
)
)
server <- function(input, output, session) {
observeEvent(input$addSliderModule, {
#what goes here
})
}
shinyApp(ui, server)
在闪亮小组上交叉发布