这是我首次尝试闪亮。我正在创建一个仪表板,它将“日期范围”和“变量名称”作为用户输入并显示图表。沿x轴的日期和沿y轴的值。我正在使用rCharts库制作情节。
csv文件中的示例数据集:
Date Total_Orders Delivered_orders Cancelled_orders NEW_USERS_COUNT
2015-04-30 23 12 2 21
2015-05-01 43 21 12 32
2015-05-02 32 13 10 30
2015-05-03 43 32 7 14
2015-05-04 43 22 3 21
2015-05-05 32 21 1 22
我写了ui.R和script.R如下。但是它显示了ui而不是主体中的情节。
我的代码:
ui.R
library("shiny")
library("shinydashboard")
require(rCharts)
options(RCHART_LIB = 'polycharts')
dashboardPage(
dashboardHeader(title = "Dashboard"),
dashboardSidebar(
dateRangeInput("daterange", "Select Date range:",
start = "2001-01-01",
end = "2010-12-31"),
selectInput("var", "Choose a variable to display",
choices = c('Total_Orders' = 'Total_Orders',
'Delivered_orders' = 'Delivered_orders',
'Cancelled_orders' = 'Cancelled_orders',
'NEW_USERS_COUNT' = 'NEW_USERS_COUNT'),
selected = "Total_Orders")
),
dashboardBody(
showOutput("chart1", "polycharts"),
)
)
server.R
library("shiny")
library("rCharts")
options(RCHART_WIDTH = 800)
file <- read.csv('file path.csv', header = TRUE)
shinyServer(function(input, output)
{output$chart1 <- renderChart({
date <- input$daterange
data <- switch(input$var,
'Total_Orders' = file$Total_Orders,
'Delivered_orders' = file$Delivered_orders,
'Cancelled_orders' = file$Cancelled_orders,
'NEW_USERS_COUNT' = file$NEW_USERS_COUNT)
rPlot(x = list(var = "date"), y = "data",
data = file, type = 'bar')
})
})
有没有更好的方法在仪表板中显示情节?