闪亮的仪表板Tabitem不显示

时间:2018-12-10 14:49:28

标签: r shinydashboard

我有4个标签,分别是“数据”,“摘要”,“预测”和“描述”,但仪表板仅显示了“数据”和“摘要”的输出。

我不知道可能是什么问题,但是当我仅将Tabitem放在“数据”上时,它将显示所有输出,但显示在同一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))
  })

})

1 个答案:

答案 0 :(得分:0)

已经解决了!!我知道是什么问题。 标签名不应有空格大声笑

相关问题