【问题标题】:shiny dashboard tabitem not showing闪亮的仪表板 tabitem 没有显示
【发布时间】:2019-05-11 11:55:28
【问题描述】:

我有 4 个 tabitem,分别是“datas”、“summary”、“prediction”和“description”,但仪表板只显示“datas”和“summary”的输出。

我不知道可能的问题是什么,但是当我只将 tabitems 放在“datas”上时,它会显示每个输出但在同一个 tabitem 中。我试图在任何地方找到解决方案,但没有一个可以解决我的问题。源代码如下所示。

ui.r

library(shinydashboard)
library(DT)

shinyUI(dashboardPage
        (
          # skin <- Sys.getenv("DASHBOARD_SKIN"),
          # skin <- tolower(skin),
          # if (skin == "")
          skin = "blue", 

      dashboardHeader(
        title = "Price Prediction of Travel Package on Upcoming Holidays",
        titleWidth = 600
      ),

      dashboardSidebar(
        #sidebarSearchForm(label = "Search...", "searchText", "searchButton"),
        sidebarMenu(
          menuItem("Data", tabName = "datas"),
          menuItem("Predictive Analytics", tabName = "Predictive Analytics"),
          menuItem("Summary of Predictive Analytics", tabName = "Summary"),
          menuItem("Descriptive Analytics", tabName = "Descriptive Analytics")
        )
      ),

      dashboardBody(
        tabItems(
          tabItem(tabName = "datas",
                  titlePanel("Travel Package Price in every State in Malaysia on Public Holidays from 2018 to 2019"),

                  fluidRow(
                    DT::dataTableOutput("data")
                  )
          ),
          tabItem(tabName = "Summary",
                  box(
                    width = 6,
                    title = "Predicted Price vs Original Price", background = "maroon", height = 500,
                    plotOutput("predictplot")
                  ),
                  box(
                    width = 6,
                    title = "Residuals vs Fitted", background = "purple", height = 500,
                    plotOutput("scatplot")
                    # height = 250
                  )
          ),
          tabItem(tabName = "Predictive Analytics",
                  titlePanel("Predicted Price vs Original Price"),
                  fluidRow(

                    DT::dataTableOutput("prediction")
                  )
          ),
          tabItem(tabName = "Descriptive Analytics",
                  titlePanel("Data Visualizations"),
                  fluidRow(
                    column(4, selectInput("variable", "Select Variable:",
                                          c("Holidays", "States"))
                    )
                  ),
                  box(
                    h3(textOutput("caption")),
                    plotOutput("description")
                  )
          ))       
      )
    )
)

server.r

    shinyServer(function(input, output) {

  mydata <- read.csv(file="C:/Users/tyra/Documents/expedia.csv", sep=',', h=T)

  set.seed(222)
  ind <- sample(2, nrow(mydata), replace = T, prob = c(0.7, 0.3))
  train <- mydata[ind==1,]
  test <- mydata[ind==2,]
  model = lm(Price ~., data = train)
  model1 <- lm(Price ~., data = test)

  Predicted_Price = predict(model1)
  Original_Price = test$Price
  Holidays = test$Holidays
  States = test$States
  df1 = data.frame(Original_Price, Predicted_Price, Holidays, States)


  output$data <- DT::renderDataTable(DT::datatable({
    mydata
  }))

  formulaText <- reactive({
    paste("Price ~", input$variable)
  })

  output$caption <- renderText({
    formulaText()
  })

  output$description <- renderPlot({
    boxplot(as.formula(formulaText()),
            data = mydata,pch = 19)
  })

  output$prediction <- DT::renderDataTable(DT::datatable({
    df1
  }))

  output$predictplot <- renderPlot({
    plot(predict(model1), test$Price)
  })


  output$scatplot <- renderPlot({
    plot(fitted(model1),residuals(model1))
  })

})

【问题讨论】:

    标签: r shinydashboard


    【解决方案1】:

    已经解决了!!我知道出了什么问题。 tabname 不应该有空格 lol

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 2018-05-18
      • 1970-01-01
      • 2018-12-21
      • 2016-09-07
      • 2015-04-22
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      相关资源
      最近更新 更多