相关疑难解决方法(0)

闪亮 - 由动态生成的输入触发的observe()

我有一个闪亮的代码生成selectInputs,每个selectInput生成图标题.问题是我不知道如何用动态生成的按钮触发observe().我使用的解决方法是在代码上写入每个selectInput的输入[[]]触发器以启动观察.是否可以从所有生成的输入中触发observe()?

library(shiny)
library(shinydashboard)


ui <- dashboardPage(
  dashboardHeader(title = "Dynamic selectInput"),
  dashboardSidebar(
    sidebarMenu(
      menuItemOutput("menuitem")
    )
  ),
  dashboardBody(
    numericInput("graph_tytle_num","Number of Graph Title elements",value = 1,min = 1,max = 10),
    uiOutput("graph_title"),
    plotOutput("plot")
  )
)

server <- function(input, output, session) {
  output$menuitem <- renderMenu({
    menuItem("Menu item", icon = icon("calendar"))
  })


  #elements of graphic titles  
  output$graph_title <- renderUI({
    buttons <- as.list(1:input$graph_tytle_num)
    buttons <- lapply(buttons, function(i)

      column(3,
        selectInput(inputId = paste0("title_element",i),
                    label = paste("Title element",i),
                    choices = paste0(LETTERS[i],seq(1,i*2)),
                    selected = 1)
      )
    )
  })


  observe({

    #Can this …
Run Code Online (Sandbox Code Playgroud)

r shiny

7
推荐指数
1
解决办法
2577
查看次数

标签 统计

r ×1

shiny ×1