我開發一個閃亮的應用程序,我希望看起來像下面的圖片: 格式/對齊rCharts(nvd3)閃亮的應用
然而,當我試圖做到這一點,我只能夠得到下面的表格:
我正在尋找如何使輸出整齊地收集,並希望得到任何幫助。我在這裏看了一些其他類似的問題,即。 this和this,但不認爲他們回答我的問題(第一次談到增加mainPanel
,但我使用FludiPage
和FluidRows
。我以爲列和行會自動調整爲屏幕大小,並且設計了12列?。以適應屏幕尺寸,但顯然我錯了
非常感謝您的幫助
的複製/粘貼Server.R文件道歉,這是一個有點長:
#
#
# load libraries, scripts, data
library(shiny)
library(shinyapps)
library(shinydashboard)
library(dplyr)
library(tidyr)
library(lubridate)
library(htmlwidgets)
options(shiny.trace = TRUE,
shiny.maxRequestSize=300*1024^2)
## body of shiny server side program
shinyServer(function(input, output, session) {
dataList <- reactive({
if(is.null(input$uploadFile)){
return(NULL)
}
uploadFileInfo <- input$uploadFile
uploadData <- read.csv(uploadFileInfo$datapath, header = TRUE, stringsAsFactors = FALSE)
uploadedData <- tbl_df(uploadData) %>%
mutate(yearValue = year(dateValues), monthValue = month(dateValues))
sumData1 <- uploadedData %>%
select(yearValue, earnPts, earnCount, redemPts, redemCount, churnCount, acquisCount) %>%
gather(metrics, totals, -yearValue) %>%
group_by(yearValue, metrics) %>%
summarise(yearlyTotals = sum(totals)) %>%
arrange(yearlyTotals)
sumData2 <- uploadedData %>%
select(yearValue, monthValue, earnPts, earnCount, redemPts, redemCount, churnCount, acquisCount) %>%
gather(metrics, totals, -c(yearValue, monthValue)) %>%
group_by(yearValue, monthValue, metrics) %>%
summarise(yearmonthTotals = sum(totals)) %>%
arrange(yearValue, monthValue) %>%
group_by(yearValue, metrics) %>%
mutate(cumulatives = cumsum(yearmonthTotals))
sumData3 <- uploadedData %>%
select(yearValue, monthValue, earnPts, earnCount, redemPts, redemCount, churnCount, acquisCount) %>%
group_by(yearValue, monthValue) %>%
summarise_each(funs(mean)) %>%
round()
sumData4 <- uploadedData %>%
group_by(dateValues) %>%
summarise_each(funs(sum))
earnData <- sumData4 %>%
select(earnPts, earnCount)
row.names(earnData) <- sumData4$dateValues
redempData <- sumData4 %>%
select(redemPts, redemCount)
row.names(earnData) <- sumData4$dateValues
custData <- sumData4 %>%
select(churnCount, acquisCount)
row.names(earnData) <- sumData4$dateValues
sumData5 <- uploadedData %>%
group_by(dateValues) %>%
summarise_each(funs(sum))
earnTSData <- sumData5 %>%
select(earnPts, earnCount)
row.names(earnTSData) <- sumData5$dateValues
redemTSData <- sumData5 %>%
select(redemPts, redemCount)
row.names(redemTSData) <- sumData5$dateValues
custTSData <- sumData5 %>%
select(acquisCount, churnCount)
row.names(custTSData) <- sumData5$dateValues
dfList <- list(sumData1 = sumData1, sumData2 = sumData2, sumData3 = sumData3,
sumData4 = sumData4, earnData = earnData, redempData = redempData,
custData = custData, sumData5 = sumData5, earnTSData = earnTSData,
redemTSData = redemTSData, custTSData = custTSData)
return(dfList)
})
### The main chart
output$outlinesChart <- renderChart2({
myData <- dataList()$sumData1
mainPlot <- nPlot(yearlyTotals ~ metrics,
group = 'yearValue', data = myData, type = 'multiBarChart')
mainPlot$chart(margin=list(left=100))
rm(myData)
return(mainPlot)
})
### Information boxes
output$infoBox1 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("line-chart"),
color = "blue"
)
})
output$infoBox2 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("line-chart"),
color = "blue"
)
})
output$infoBox3 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("line-chart"),
color = "blue"
)
})
output$infoBox4 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("line-chart"),
color = "blue"
)
})
output$infoBox5 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("smile-o"),
color = "blue"
)
})
output$infoBox6 <- renderInfoBox({
infoBox(
"Progress", 10*2, icon = icon("frown-o"),
color = "purple", fill = TRUE
)
})
### Cumulative chart for points earned
output$cEarnPtsChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'earnPts')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
### Cumulative chart for count of earn transactions
output$cEarnCountChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'earnCount')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
### Cumulative chart for points redeemed
output$cRedemPtsChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'redemPts')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
### Cumulative chart for count of redemption transactions
output$cRedemCountChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'redemCount')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
### Cumulative chart for Customer Acquisition
output$cAcquisChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'acquisCount')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
### Cumulative chart for Customer Acquisition
output$cChurnChart <- renderChart2({
myData <- dataList()$sumData2
interimData <- myData %>% filter(metrics == 'churnCount')
myPlot <- nPlot(cumulatives ~ monthValue, group = 'yearValue',
data = interimData, type = 'lineChart')
rm(myData)
rm(interimData)
return(myPlot)
})
})
的ui.R文件:
### load libraries
library(shiny)
library(shinythemes)
### body for Shiny UI
shinyUI(navbarPage("My Sample Dashboard", theme = shinytheme('readable'), inverse = TRUE,
tabPanel("Overview Section",
fluidRow(
column(6,
##current app only supports CSV, since this is a proof of concept...
fileInput(inputId = 'uploadFile', label = 'Please upload your file')
)
),
fluidRow(
column(3,
h4('Main Chart goes here'),
showOutput('outlinesChart', 'nvd3')
),
column(3, offset = 5,
h5('Info boxes go here'),
infoBoxOutput('infoBox1'),
infoBoxOutput('infoBox2'),
infoBoxOutput('infoBox3'),
infoBoxOutput('infoBox4'),
infoBoxOutput('infoBox5'),
infoBoxOutput('infoBox6')
)
),
hr(),
fluidRow(
column(2,
h5('Earned Points chart goes here'),
showOutput('cEarnPtsChart', 'nvd3')
),
column(2, offset = 4,
h5('Earn Count chart goes here'),
showOutput('cEarnCountChart', 'nvd3')
)
),
fluidRow(
column(2,
h5('Redeemed Points chart goes here'),
showOutput('cRedemPtsChart', 'nvd3')
),
column(2, offset = 4,
h5('Redemption Count chart goes here'),
showOutput('cRedemCountChart', 'nvd3')
)
),
fluidRow(
column(2,
h5('Customer Acquisition chart goes here'),
showOutput('cAcquisChart', 'nvd3')
),
column(2, offset = 4,
h5('Customer Churn chart goes here'),
showOutput('cChurnChart', 'nvd3')
)
)
),
tabPanel("Details Section"),
tabPanel("Experiments Section"))
)
編輯:
以下是生成的CSV文件的代碼要被饋送到這個程序。
earnPtsRange <- 12000:18000
earnCountRange <- 1000:10000
redemPtsRange <- 10000:20000
redemCountRange <- 10000:20000
churnRange <- 1000:10000
acquisitionRange <- 800:15000
### obtained from Dirk Eddelbuettel: https://stackoverflow.com/questions/14720983/efficiently-generate-a-random-sample-of-times-and-dates-between-two-dates
generateDates <- function(N, st="2014/01/01", et="2015/08/31") {
st <- as.POSIXct(as.Date(st))
et <- as.POSIXct(as.Date(et))
dt <- as.numeric(difftime(et,st,unit="sec"))
ev <- sort(runif(N, 0, dt))
rt <- st + ev
rt[order(rt)]
as.Date(rt)
}
## generate data; 10 readings for each month out of 20 months
dateValues <- generateDates(200)
earnPts <- sample(x = earnPtsRange, size = 190)
earnCount <- sample(x = earnCountRange, size = 190)
redemPts <- sample(x = redemPtsRange, size = 190)
redemCount <- sample(x = redemCountRange, size = 190)
churnCount <- sample(x = churnRange, size = 190)
acquisCount <- sample(x = acquisitionRange, size = 190)
## merge the generated data
toyData <- data.frame(dateValues = dateValues, earnPts = earnPts, earnCount = earnCount, redemPts = redemPts, redemCount = redemCount, churnCount = churnCount,
acquisCount = acquisCount)
## write the data to a CSV file
write.csv(x = toyData, file = './toyDataset.csv', row.names = FALSE)
非常感謝提前。
任何R-善良的靈魂嗎? – 2015-04-02 22:28:43