当menuItem的名称可以在闪亮的 Jmeter 板中更改时,使用actionButton()从一个menuItem移动到另一个menuItem

h5qlskok  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(149)

我有下面的shiny应用程序,我想通过输入第一个menuItem()textInput()来设置第二个menuItem()的名称。然后通过单击actionButton()移动到它。还有为什么我使用的textOutput()显示在图标下面,而不是像第一个一样显示在它旁边?

## app.R ##
library(shiny)
library(shinydashboard)


ui <- dashboardPage(
  dashboardHeader(
   
    
  ),
  dashboardSidebar(
    collapsed = TRUE,
    sidebarMenu(
      id="inTabset",
      menuItem("Workspace", tabName = "workspace", icon = icon("upload")),
      
      menuItemOutput("tab2")
      
      
      
      
    )
  ),
  dashboardBody(
    
    tabItems(
      # First tab content
      tabItem(tabName = "workspace",
              fluidRow(
              
                         
                        
                           
                           textInput("name", "", value = "Process model", placeholder = NULL),
                           actionButton("nextt","Next", icon("paper-plane") 
                                        )

                         
                       )
                       
                )
                
      ),
      
     
      tabItem(
        tabName = "Process model",
        
    )
  )

)

server <- function(input, output,session) {
  output$tab2 <- renderMenu({
    menuItem(text = input$name, tabName = "Process model", icon = icon("diagram-project"))  
  })
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process model")
  })
  
  
  
  output$tabtitle <- renderText({
    if (input$name == "") {
      "Process model"
    } else {
      paste(input$name)
    }
  })
  
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process model")
  })
  
  
  
}

shinyApp(ui, server)
os8fio9y

os8fio9y1#

要动态创建和命名menuItem,可以使用renderMenumenuItemOutput

library(shinydashboard)
library(shiny)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
    sidebarMenu(
      id = "inTabset",
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItemOutput("tab2")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "dashboard",
        textInput("name", "Create a name for your process", value = "", placeholder = NULL),
        actionButton("nextt", "Next")
      ),
      tabItem(
        tabName = "widgets"
      )
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "widgets")
  })
  
  output$tab2 <- renderMenu({
    menuItem(text = input$name, tabName = "widgets", icon = icon("th"))  
  })
  
  output$tabtitle <- renderText({
    if (input$name == "") {
      "Name of process"
    } else {
      paste(input$name)
    }
  })
  
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "widgets")
  })
}

shinyApp(ui, server)

相关问题