簡體   English   中英

R Shiny 儀表板只加載一次標簽

[英]R Shiny dashboard loading tabs only once

我開始構建我的第一個閃亮的應用程序,但現在正在為一種奇怪的行為而苦苦掙扎。 首先,當我最初加載應用程序時,默認情況下沒有選擇選項卡。 其次,當單擊側邊欄上的任何菜單時,它僅在第一次顯示正文。 當我從“概覽”轉到“數據透視表”並返回時,正文是空白的。 我錯過了什么? 下面是我使用的代碼。

library(shiny)
library(shinydashboard)

df<-data.frame(a=c(1,2,3,4),
               b=c("A","B","C","D"))

###################Beginn der App################
ui <- dashboardPage(
  # Application title
  dashboardHeader(),

  ##----DashboardSidebar----

  dashboardSidebar(
    menuItem("Overview", tabName = "overview",selected=TRUE),
    menuItem("Pivot-Tabelle", tabName = "pivot"),
    menuItem("Test", tabName = "farmer")
  ),

  ##----DashboardBody----
  dashboardBody(
    tabItems(
      ##----TabItem: Overview----
      tabItem(tabName="overview",
              fluidRow(
                valueBoxOutput("A"),
                valueBoxOutput("B")
              )
      ),
      ###----TabItem:Pivot----
      tabItem(tabName = "pivot",
              ##Pivot
              column(6,offset=4,titlePanel("Daten-Explorer")),
              column(12,
                     mainPanel(
                       rpivotTableOutput("pivot")
                     )
              )
      ),
      ##----TabItem:Test----
      tabItem(tabName = "Test",
              h2("In Progress"))
    )
  )
)

server <- function(input, output) {
  ##----server:overview----
  output$A<-renderValueBox({
    valueBox(
      paste0(25, "%"), "Landwirte in der Datenbank", icon = icon("Person"),
      color = "purple"
    )
  })
  output$B<-renderValueBox({
    valueBox(
      paste0(55, "%"), "Landwirte in der Datenbank", icon = icon("Person"),
      color = "purple"
    )
  })



  ##----server:pivot----
  output$pivot <- renderRpivotTable({
    rpivotTable(data = df)
  })
}

# Run the application
shinyApp(ui = ui, server = server)

這似乎有效。 您的menuItem需要有sidebarMenu 此外,您需要將tabName更改為farmer以使其與您的menuItem匹配。 我不認為你需要mainPanel在那里(你可以使用mainPanelsidebarPanel作為的一部分sidebarLayout如果你想要一個布局-見布局選項)。 看看這是否適合你。

library(shiny)
library(shinydashboard)
library(rpivotTable)

df<-data.frame(a=c(1,2,3,4),
               b=c("A","B","C","D"))

###################Beginn der App################
ui <- dashboardPage(
  # Application title
  dashboardHeader(),

  ##----DashboardSidebar----

  dashboardSidebar(
    sidebarMenu(
      menuItem("Overview", tabName = "overview",selected=TRUE),
      menuItem("Pivot-Tabelle", tabName = "pivot"),
      menuItem("Test", tabName = "farmer")
    )
  ),

  ##----DashboardBody----
  dashboardBody(
    tabItems(
      ##----TabItem: Overview----
      tabItem(tabName="overview",
              fluidRow(
                valueBoxOutput("A"),
                valueBoxOutput("B")
              )
      ),
      ###----TabItem:Pivot----
      tabItem(tabName = "pivot",
              ##Pivot
              column(6,offset=4,titlePanel("Daten-Explorer")),
              column(12,
                     #mainPanel(
                       rpivotTableOutput("pivot")
                     #)
              )
      ),
      ##----TabItem:Test----
      tabItem(tabName = "farmer",
              h2("In Progress"))
    )
  )
)

server <- function(input, output) {
  ##----server:overview----
  output$A<-renderValueBox({
    valueBox(
      paste0(25, "%"), "Landwirte in der Datenbank", icon = icon("Person"),
      color = "purple"
    )
  })
  output$B<-renderValueBox({
    valueBox(
      paste0(55, "%"), "Landwirte in der Datenbank", icon = icon("Person"),
      color = "purple"
    )
  })
  ##----server:pivot----
  output$pivot <- renderRpivotTable({
    rpivotTable(data = df)
  })
}

# Run the application
shinyApp(ui = ui, server = server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM