我可以在一个Shinydashboard模块中包含多个UI元素吗?

中,将放入menuItem(menuSubItems())的{​​{1}}部分有极大的便利。但是我希望将UI和Server的几个元素编码到模块中,这样我才能坚持使用框架...如果没有为单个模块创建多个UI函数,我看不到一种清晰的方法。我已经在dashboardSidebar()上看到了shinydashboard golem的示例,但这个示例太简单了,没有用。

例如,有什么方法可以做到这一点?

以模块格式:

github

有什么办法可以使这种事情起作用?该小部件未显示,可能是因为我认为模块化框架不允许我为一项功能制作两个不同的UI元素。

luyan8883 回答:我可以在一个Shinydashboard模块中包含多个UI元素吗?

好吧,所以我得到了这项工作。。。我不知道我的应用程序的复杂性是否可以解决这个问题,但对于希望这样做的任何人,也许这会有所帮助:

library(shiny)
library(shinydashboard)
library(DT)

mod_myAppSidebar_ui<-function(id) {
  ns <- NS(id)
  tagList(menuItem("Attributes",tabName="ourdata",textInput(ns("textSearch"),"SQL Search String",value = ""),actionButton(ns("go"),label = "Search")))
}

mod_myAppBody_ui<-function(id) {
  ns <- NS(id)
  tagList(fluidRow(title = "Data Selected",box(DT::dataTableOutput(outputId = ns("OutputData")))))
}

mod_myApp_server<-function(input,output,session,r) {
  ns <- session$ns

  observeEvent( input$go,{
    r$textSearch<-input$textSearch
    print(r$textSearch)
    somedata=data.frame(Rows=letters,Indexes=1:length(letters))
    r$chooseData<-somedata[grepl(tolower(input$textSearch),somedata$Rows),]
  })

  output$OutputData<-DT::renderDataTable(r$chooseData)

}

ui <- dashboardPage(header = dashboardHeader(title = "Rosetta"),sidebar = dashboardSidebar(mod_myAppSidebar_ui("MySearch")),body = dashboardBody(mod_myAppBody_ui("MySearch")))

server <- function(input,session) {
  r<-reactiveValues()
  callModule(mod_myApp_server,"MySearch",r)
}

shinyApp(ui,server)
本文链接:https://www.f2er.com/2594848.html

大家都在问