微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

服务器端选择在 R Shiny 应用程序中不起作用

如何解决服务器端选择在 R Shiny 应用程序中不起作用

Here is the main / only docs on server-side selectize 来自 RStudio。按照本文中的示例,我创建了下面的示例。下面代码的主要目标是将输入呈现为服务器大小的选择输入。请注意,select 选项的获取app.R 文件 顶部附近全局发生 - 我们获取命名字符向量 namelist_nba 的数据,我们将其用作 { {1}}。为了重现性,我已经注释掉了我们的数据获取代码并对前 20 个响应进行了硬编码:

app.R - 您应该能够运行它。

choices

当我们运行这个应用程序时,选择输入目前根本不起作用。我无法输入玩家姓名,并且单击该框不会显示任何下拉列表(尽管它确实会在几分之一秒内显示一个很小的空下拉列表)。我们如何更新我们的代码,以便服务器端选择在这里工作?

请注意,我们的代码示例通过使用闪亮的模块 all documented here 变得更加复杂。

解决方法

虽然 updateSelectizeInput() 似乎不起作用,但您可以在 selectizeInput 中调用 renderUI 并使其起作用。试试这个

namelist_nba <- c(`A.C. Green` = 920L,`A.J. Bramlett` = 1920L,`A.J. Davis` = 203667L,`A.J. Guyton` = 2062L,`Aaron Best` = 1628700L,`Aaron Brooks` = 201166L,`Aaron Craft` = 203905L,`Aaron Epps` = 1629200L,`Aaron Gordon` = 203932L,`Aaron Gray` = 201189L,`Aaron Harrison` = 1626151L,`Aaron Holiday` = 1628988L,`Aaron Jackson` = 1628935L,`Aaron Johnson` = 203638L,`Aaron McKie` = 243L,`Aaron Miles` = 101223L,`Aaron Nesmith` = 1630174L,`Aaron Pettway` = 202925L,`Aaron Thomas` = 1628045L,`Aaron White` = 1626206L)



ui_player_profile <- function(id) {
  ns <- NS(id)
  tagList(
    uiOutput(ns("playerinput"))
    #selectInputize(inputId = ns("player_input"),label = 'Player Search: ',choices = NULL)
  )
}

# server module for "player profile" page
server_player_profile <- function(id) {
  moduleServer(
    id,function(input,output,session) {
      ns <- session$ns
     
        # updateSelectizeInput(
        #   session,#   inputId = ns('player_input'),#   #inputId = session$ns('player_input'),#   choices = namelist_nba,#   selected = namelist_nba[1] #,server = TRUE
        #   )
     
      output$playerinput <- renderUI({
        selectizeInput(inputId = ns("player_input"),choices = namelist_nba,selected = namelist_nba[1])
      })
      
    }
  )
}

# create body and sidebar
ui_body <- dashboardBody()

# note use of NS() and modules

ui_sidebar <- dashboardSidebar(
  
  sidebarMenu(
    id = "sidebarMenu",menuItem("These Pages",tabName = "team",menuSubItem("Player Profile",tabName = "player_profile_nba"),# conditionalPanel(
             #   "input.sidebarMenu === 'player_profile_nba'",#   class = NULL,ui_player_profile('nba_player_profile')
             
             # )
    )
  )
)

# ui is where we combine header,sidebar,body
ui <- dashboardPage(
  title="Dashboard Title",dashboardHeader(
    title = div("Our Databoard header title"),titleWidth = 300),ui_sidebar,ui_body
)

# shinyserver is where we combine all of our server modules...
server <- shinyServer(function(input,session) {
  observeEvent(input$sidebarMenu,{
    print(paste0("sidebarMenu tabName: ",input$sidebarMenu))
  })
  
  server_player_profile(id = 'nba_player_profile')
})


# and return / run the app
shinyApp(ui = ui,server = server)

output

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。