如何将sliderInput动态添加到您的应用程序中?

如何将sliderInput动态添加到您的应用程序中?,r,shiny,R,Shiny,使用shiny,我上传了一个csv文件,根据列名,我需要向ui添加滑块 sidebarPanel( fileInput('file1', 'Upload CSV File to Create a Model', accept=c('text/csv','text/comma-separated-

使用shiny,我上传了一个csv文件,根据列名,我需要向ui添加滑块

                        sidebarPanel(
                                  fileInput('file1', 'Upload CSV File to Create a Model',
                                            accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
                                  tags$hr(),
                                  checkboxInput('header', 'Header', TRUE),
                                  fluidRow(
                                    column(6,checkboxGroupInput("xaxisGrp","X-Axis:", c("1"="1","2"="2"))),
                                    column(6,radioButtons("yaxisGrp","Y-axis:", c("1"="1","2"="2")))
                                  ),
                                  radioButtons('sep', 'Separator',
                                               c(Comma=',', Semicolon=';',Tab='\t'), ','),
                                  radioButtons('quote', 'Quote',
                                               c(None='','Double Quote'='"','Single Quote'="'"),'"'),
                                  uiOutput("choose_columns")
                                )
如您所见,有xaxisGrp和yaxisGrp。xasixGrp在我上传的csv文件中有列名

我需要在xasisGrp中动态添加尽可能多的sliderInput,减去yaxisGrp中的列名。比如说

xasisGrp has "Heap", "CPU", "Volume",
我需要能够生成3个幻灯片,如下所示:

sliderInput("Heap", "Heap Growth %",min=0, max=100, value=0,post="%"),
sliderInput("CPU", "CPU Growth %", min=0, max=100, value=0,post="%"),
sliderInput("Volume", "Volume Growth%", min=0, max=100, value=0,post="%"),

你知道我该怎么做吗?

这里是一个简单的例子

library(shiny)

xAxisGroup <- c("Heap", "CPU", "Volume")

ui <- shinyUI(fluidPage(

   titlePanel("Dynamic sliders"),

   sidebarLayout(
      sidebarPanel(
          # Create a uiOutput to hold the sliders
        uiOutput("sliders")
      ),

      mainPanel(
         plotOutput("distPlot")
      )
   )
))

server <- shinyServer(function(input, output) {

    #Render the sliders
    output$sliders <- renderUI({
        # First, create a list of sliders each with a different name
        sliders <- lapply(1:length(xAxisGroup), function(i) {
            inputName <- xAxisGroup[i]
            sliderInput(inputName, inputName, min=0, max=100, value=0, post="%")
        })
        # Create a tagList of sliders (this is important)
        do.call(tagList, sliders)
    })


   output$distPlot <- renderPlot({
      hist(rnorm(100), col = 'darkgray', border = 'white')
   })
})

shinyApp(ui = ui, server = server)
库(闪亮)

xAxisGroup这里是一个快速示例

library(shiny)

xAxisGroup <- c("Heap", "CPU", "Volume")

ui <- shinyUI(fluidPage(

   titlePanel("Dynamic sliders"),

   sidebarLayout(
      sidebarPanel(
          # Create a uiOutput to hold the sliders
        uiOutput("sliders")
      ),

      mainPanel(
         plotOutput("distPlot")
      )
   )
))

server <- shinyServer(function(input, output) {

    #Render the sliders
    output$sliders <- renderUI({
        # First, create a list of sliders each with a different name
        sliders <- lapply(1:length(xAxisGroup), function(i) {
            inputName <- xAxisGroup[i]
            sliderInput(inputName, inputName, min=0, max=100, value=0, post="%")
        })
        # Create a tagList of sliders (this is important)
        do.call(tagList, sliders)
    })


   output$distPlot <- renderPlot({
      hist(rnorm(100), col = 'darkgray', border = 'white')
   })
})

shinyApp(ui = ui, server = server)
库(闪亮)

这里的xAxisGroup是一个动态生成多个
textInput
的示例,但其思想是相同的。你需要在
ui.R
中使用
uiOutput
renderUI
lappy
do.call
server.R
@warmoverflow中,我查看了关于文本输入的帖子,没有关注它。你能让我开始吗?下面是一个动态生成多个
textInput
的示例,但想法是一样的。你需要在
ui.R
中使用
uiOutput
renderUI
lappy
do.call
server.R
@warmoverflow中,我查看了关于文本输入的帖子,没有关注它。你们能让我开始吗?滑杆太小了,我不知道它是否工作?一个简单的问题。我需要在另一个函数中引用这些滑块来做一些其他工作。我需要遍历每个滑块的值并计算其他一些值。只需像普通输入那样使用该值
input$Heap
etc@XiongbingJin非常感谢你的帮助。。您或其他人是否有Lappy/Do.call Approach滑块的purrr替代品滑块太小,我无法判断它是否工作?一个简单的问题。我需要在另一个函数中引用这些滑块来做一些其他工作。我需要遍历每个滑块的值并计算其他一些值。只需像普通输入那样使用该值
input$Heap
etc@XiongbingJin非常感谢你的帮助。。您或其他任何人是否有一种purrr方法来替代lappy/Do.call方法