代码当前生成仪表板和图表的侧面板,它还生成一个图。 (在最后一行中被称为第一)。如果有人对如何使用闪亮的仪表板在两个不同的选项卡上生成两个单独的图表有任何建议,那将非常感激。撕掉我的头发!
https://lot1bct.shinyapps.io/lot1bct/
我目前的状态,减去“燃料”标签和第二个图,以供参考我的目标。
下面的代码模拟了第二个绘图代码以及“燃料”选项卡中的附加仪表板代码,实时版本没有。
## app.R ##
library(shinydashboard)
library(shiny)
library(ggplot2)
dataset <- testData
fuelData <- fuelDataCSV
tyreData <- tyreDataCSV
ui <- dashboardPage(
skin="green",
dashboardHeader(title = "Strategy Dashboard v0.1",
dropdownMenu(type = "tasks", badgeStatus = "success",
taskItem(value = 10, color = "green",
"Documentation"
),
taskItem(value = 30, color = "aqua",
"UI"
),
taskItem(value = 15, color = "yellow",
"Data Developmentt"
)
)),
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Home", tabName = "home", icon = icon("home")),
menuItem("Tyres", tabName = "tyres", icon = icon("circle-o")),
menuItem("Fuels and Lubericants", tabName = "fuel", icon = icon("flask")),
menuItem("Times", tabName = "times", icon = icon("clock-o")),
menuItem("Documentation", tabName = "documentation", icon = icon("sticky-note-o")),
menuItem("Downloads", tabName = "downloads", icon = icon("download")),
# Custom CSS to hide the default logout panel
tags$head(tags$style(HTML('.shiny-server-account { display: none; }'))),
# The dynamically-generated user panel
uiOutput("userpanel")
)
),
## Header Content
## Body content
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "home",
h2("UI Tests"), p("This published version is the first test build (version 0.1).")
),
# Second tab content
tabItem(tabName = "tyres",
h2("Tyre data sets"), fluidPage(
sidebarPanel(
sliderInput('sampleSize', 'Sample Size (Laps)', min=1, max=nrow(tyreData),
value=min(20, nrow(tyreData)), step=1, round=0),
selectInput('x', 'X', names(tyreData)),
selectInput('y', 'Y', names(tyreData), names(tyreData)[[2]]),
selectInput('color', 'Color', c('None', names(tyreData))),
checkboxInput('density', 'Density'),
checkboxInput('trend', 'Trend')
),
mainPanel(
plotOutput('plotT')
)
)
),
# Third tab content
tabItem(tabName = "fuel",
h2("Fuel and Lubricant data sets"),
fluidPage(
sidebarPanel(
sliderInput('sampleSize', 'Sample Size (Laps)', min=1, max=nrow(fuelData),
value=min(20, nrow(fuelData)), step=1, round=0),
selectInput('x', 'X', names(fuelData)),
selectInput('y', 'Y', names(fuelData), names(fuelData)[[2]]),
selectInput('color', 'Color', c('None', names(fuelData))),
checkboxInput('density', 'Density'),
checkboxInput('trend', 'Trend')
),
mainPanel(
plotOutput('plotF')
)
)
),
# Fourth tab content
tabItem(tabName = "times",
h2("Times data sets")
),
# Fifth tab content
tabItem(tabName = "documentation",
h2("Documentation")
),
# Sixth tab content
tabItem(tabName = "downloads",
h2("Downloads")
)
)
)
)
tyrePlot <- function(input, output) {
tyreData <- reactive({
tyreDataCSV[sample(nrow(tyreDataCSV), input$sampleSize),]
})
output$plotF <- renderPlot({
p <- ggplot(tyreData(), aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
if (input$density)
p <- p + geom_density_2d()
if (input$trend)
p <- p + geom_smooth()
print(p)
}, height=700)
}
fuelPlot <- function(input, output) {
fuelData <- reactive({
fuelDataCSV[sample(nrow(fuelDataCSV), input$sampleSize),]
})
output$plotF <- renderPlot({
p <- ggplot(fuelData(), aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
if (input$density)
p <- p + geom_density_2d()
if (input$trend)
p <- p + geom_smooth()
print(p)
}, height=700)
}
shinyApp(ui, tyrePlot, fuelPlot)