简体   繁体   English

R Shiny 应用程序的 ShinyDashboard 侧边栏中的 selectInput 反应值仍然为 Null

[英]selectInput reactive value in shinyDashboard sidebar of R shiny app remains Null

It appears the input value of a selectInput object is not updating.似乎 selectInput 对象的输入值没有更新。 I have inserted one in the sidebar menu.我在侧边栏菜单中插入了一个。 I am using shinyDashboard.我正在使用闪亮的仪表板。 here is my code.这是我的代码。

header & Sidebar标题和侧边栏

header <-
  dashboardHeader(
    title = "REPORT",
    tags$li(class = "dropdown",
            tags$style(
              HTML(
                "@import url('//fonts.googleapis.com/css?family=Libre+Baskerville:400,700|Open+Sans:400,700|Montserrat:400,700');"
              )
            )),
    disable = FALSE,
    titleWidth  = '200'
  )
header$children[[3]]$children[[3]] <-
  tags$h1("DATABASE",
          # align = 'left',
          style = "color:#FFFFFF; font-weight: bold; font-family: 'Open Sans','Libre Baskerville',Montserrat, serif;font-size: 23px;")

data_type_list<-c('in vivo','in vitro','pbpk') 
siderbar <- dashboardSidebar(
    width = 200,
    sidebarMenu(
        id = 'sidebar',
        style = "position: relative; overflow: visible;",
        menuItem(
            "TK Knowlegebase",
            tabName = 'tk',
            icon = icon('database'),
            badgeColor = "teal",
            #radioButtons("tk_data_type", "Select Data Type:",data_type_list)
            selectInput('tk_data_type',"Select Data Type",data_type_list, selected=1)
        )
    )
)

body身体

body <- dashboardBody(width = 870,
                      tags$head(
                          tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
                      ),
                      #theme = shinythemes::shinytheme("darkly"),
                      tabItems(
                          tabItem (
                              tabName = "tk",
                              mainPanel(
                    
                                  #in vivo ----
                      conditionalPanel(
                          condition ="input.tk_data_type== 'in vivo'",
                          tags$h2('vivo')
                                  ),
                      
                      # in vitro ----
                      conditionalPanel(
                          condition="input.tk_data_type== 'in vitro'",
                          tags$h2('vitro')
                          )
                       ,
                      #  pbpk ----
                      conditionalPanel(
                          condition="input.tk_data_type== 'pbpk'",
                              tags$h2('pbpk')              
                         )
                    
)))

server = function(input, output, session) {
observe({input$tk_data_type})
}
ui <- dashboardPage(title = 'ARC Toxkin App', skin = 'purple',
                    header, siderbar, body)
shiny::shinyApp(ui = ui, server = server)

I even attempted to use observe({input$tk_data_type}) in the server section to no success.我什至尝试在服务器部分使用 observe({input$tk_data_type}) 没有成功。

What I obtain is a blank page.我得到的是一个空白页。 what I wish to see is content from dashboardBody() appear.我希望看到的是来自dashboardBody() 的内容出现。

Thank you for your time感谢您的时间

UPDATE This is a short-term fix solution, thanks to user YBS.更新 这是一个短期修复解决方案,感谢用户 YBS。

vitro_tabset<-tabsetPanel(
    tabPanel("Detailed",
             "This is a test"),
    tabPanel("Phys-chem",
             "This is a test"),
    tabPanel("Exploratory",
             "This is a test"),
    tabPanel("Downloads",
             "This is a test")
)
vivo_tabset<-tabsetPanel(
    tabPanel("Detailed",
             "This is a test"),
    tabPanel("Phys-chem",
             "This is a test"),
    tabPanel("Exploratory",
             "This is a test"),
    tabPanel("Downloads",
             "This is a test")
)


siderbar <- dashboardSidebar(
    sidebarMenu(
        id = 'sidebar',
        menuItem(
            "TK Knowlegebase",
            tabName = 'tk',
            icon = icon('database'),
            badgeColor = "teal",
            selected = TRUE,
            startExpanded = TRUE,
            #radioButtons("tk_data_type2", "Select Data Type:",data_type_list),
            menuSubItem('vivo', tabName = 'vivo', icon = shiny::icon("angle-double-right"), selected = NULL),
            menuSubItem('vitro', tabName = 'vitro', icon = shiny::icon("angle-double-right"), selected = TRUE),
            menuSubItem('pbpk', tabName = 'pbpk', icon = shiny::icon("angle-double-right"), selected = NULL)
        )
    )
)

body <- dashboardBody(width = 870,
                      tabItems(
                          tabItem (tabName = "vivo",
                                     vivo_tabset),
                          tabItem(tabName='vitro',
                                # in vitro ----
                                vitro_tabset),
                          #  pbpk ----
                          tabItem(tabName='pbpk')

It appears that tabItems() and tabItem() don't work well in your program as the sidebarmenu requires minor tweaking.看起来tabItems()tabItem()在你的程序中不能很好地工作,因为侧边栏菜单需要微调。 Also, you don't need mainPanel .此外,您不需要mainPanel Try this尝试这个

data_type_list <- c("in vivo","in vitro","pbpk")

ui <- shinydashboard::dashboardPage(title = "ARC Toxkin App",  skin = "purple",
                      shinydashboard::dashboardHeader(
                      title = "REPORT" ,
                      tags$li(class = "dropdown",
                              tags$style(
                                HTML(
                                  "@import url('//fonts.googleapis.com/css?family=Libre+Baskerville:400,700|Open+Sans:400,700|Montserrat:400,700');"
                                )
                              )),
                      disable = FALSE,
                      titleWidth  = '200'
                    ),

                    shinydashboard::dashboardSidebar(width = 220,
                                                     useShinyjs(),
                      sidebarMenu(
                        id = "tabs",
                        style = "position: relative; overflow: visible;",
                        menuItem("TK Knowlegebase", tabName="tk", icon = icon("bar-chart-o"),
                          menuSubItem("TK Knowlegebase1", tabName = "tk1", icon = icon('database')),
                          selectInput("tk_data_type", label="Select Data Type", choices = data_type_list, selected=1),
                          menuSubItem("TK Knowlegebase2", tabName = "tk2", icon = icon('database'))
                          #radioButtons("tk_data_type2", "Select Data Type:",data_type_list)
                        )
                      )
                    ),

                    shinydashboard::dashboardBody( #width = 870,
                      tags$head(
                        tags$link(rel = "stylesheet", type = "text/css", href = "custom.css"),
                      ),
                      #theme = shinythemes::shinytheme("darkly"),
                      tabItems(
                        #tabItem(tabName = "tk", headerPanel('First')),
                        tabItem(tabName = "tk1",
                                fluidRow(
                                  shinydashboard::box(title = "Graphics Package", width = 12, solidHeader = TRUE, status="info",
                                  ## vivo
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'in vivo'",
                                    tags$h2(' vivo')
                                  ),

                                  ## in vitro
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'in vitro'",
                                    tags$h2(' vitro')
                                  ),
                                  ##  pbpk
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'pbpk'",
                                    tags$h2(' pbpk')
                                  ),
                                  verbatimTextOutput("tb1"),
                                  DTOutput("tb2")
                                  
                                ))
                         ),
                         tabItem(tabName = "tk2", headerPanel('Last'), DTOutput("tb3")
                                 #verbatimTextOutput("tb4")
                         )
                    )
      )
)


server <- function(input, output, session) {

  output$tb3 <- renderDT(mtcars)
  output$tb2 <- renderDT(iris)
  output$tb1 <- renderPrint({input$tk_data_type})
  output$tb4 <- renderPrint({input$tk_data_type2})

}

shinyApp(ui, server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM