Shiny:renderUI和shiny:ui输出以生成新的menuItem和新的输出,但tabItem不显示 [英] shiny:renderUI and shiny:uioutput to produce a new menuItem and a new output, but the tabItem not showing

查看:0
本文介绍了Shiny:renderUI和shiny:ui输出以生成新的menuItem和新的输出,但tabItem不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于一个actionButton创建一个新的menuItem和一个新的plotOutput,新呈现的plotOutput将根据提交的值显示一个绘图。我已经成功地生成了提交值的menuItem和umericInput小部件,但没有显示绘图和对应的表项。
以下是工作流程:

提交-&>呈现带有输入对象和plotOutput->;的menuItem;将根据呈现的输入对象显示plotOutput

第二个过程成功,但其余步骤不起作用,代码如下所示:

library(shiny)
library(shinydashboard)

## ============================================ Define ui ==================================================

header1 <- dashboardHeader(
  title = "My Dynamic Menu"
) #dashboardHeader

# DYNAMIC UI
sidebar1 <- dashboardSidebar(
  sidebarMenu(
    menuItem('aa',tabName = 'aa')
  ) ,
  sidebarMenuOutput('bb')
) #dashboardSidebar
#
body1 <- dashboardBody(
  tabItems(
    tabItem(tabName = 'aa',
            numericInput('num_input', 'number', value = 5), 
            actionButton('submit','Submit')),
    tabItem(tabName = "main", uiOutput('eee')) # put a tabItem here
  ) #tabItems
) #dashboardBody

ui <- dashboardPage(header1, sidebar1, body1)

server <- function(input, output, session) {
  dt<-eventReactive(input$submit, {
    input$num_input * 5
  })
  
  observeEvent(input$submit, {
    output$bb<-renderMenu({
      sidebarMenu(
        menuItem("Main", tabName = "main", 
                 numericInput('ddd', 'input value', value = dt()),
                 numericInput('ggg', 'another input', value=dt()+5))
      )
    })
    
    output$eee<-renderUI({
      fluidRow(
        p('hello'),
        plotOutput('fff')
      )
    })
  })
  
  
   observeEvent({
     input$ddd
     input$ggg
   },{
       output$fff<-renderPlot({
       plot(1:input$ddd, main=as.character(input$ggg))
     })
   })
  
} #server
## ============================================ Run application ============================================
shinyApp(ui, server)

如果此问题得到解决,非常感谢。

推荐答案

若要与表项链接,menuItem应仅包含menuSubItem。如果删除两个数字输入(DDD和GGG),则当您单击新创建的主菜单项时,主页将被激活。混合导航和输入不是一个好主意。

您最好将输入移动到主表项目中,或者将它们放在侧边栏的单独面板中(不在菜单中)。

为UI中的输入添加了ui输出

# DYNAMIC UI
sidebar1 <- dashboardSidebar(
  sidebarMenu(
    menuItem('aa',tabName = 'aa')
  ) ,
  sidebarMenuOutput('bb'),
  uiOutput("inputs")
) #dashboardSidebar

在服务器中为此输出添加了renderUI

output$inputs <- renderUI(tagList(
      numericInput('ddd', 'input value', value = dt()),
      numericInput('ggg', 'another input', value=dt()+5)
    ))

并从renderMenu中删除了输入

output$bb<-renderMenu({
      message("bb")
      sidebarMenu(
        menuItem("Main", tabName = "main")
      )
    })

您必须手动导航到主页才能显示绘图

这篇关于Shiny:renderUI和shiny:ui输出以生成新的menuItem和新的输出,但tabItem不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆