R - 带有 DT 和闪亮的 dygraphs
R - dygraphs with DT and shiny
这是我的第一个问题。
Here is the graph. Why my graph does not show numbers on each lines and how can I change left side axis to display numbers rather than exponential sign
此外,我还有一些关于DT、dygraphs和shiny的问题。
1. 我已经在 R 中读取了我的 csv 数据,并且只是 运行 dygraphs 作为附加图像。但是,如果我希望我的图像在鼠标停留在其上时在线条上有一些数字,我该怎么做? 已解决
2. 另外,我想更改 y 轴以显示数字而不是指数符号。 已解决
3. 我有一个关于使用 shiny 来显示我的 excel 数据的想法。因此,我使用具有数据表功能的 DT 包。此外,我如何在 shiny 中组合 DT 和 dygraphs。我的意思是当我单击数据表和 select 某些行或列时,将显示动态折线图。也许还有其他有用和方便的软件包?
4. shiny与DT.
结合的参考资料在哪里可以找到
以下是我对 R 的 test.csv 数据输入。
year month company wp wn ep en pa pan npa npan
1 2015 1 Ch 6497985 1 1471586 2 4833118 3 0 0
2 2015 1 SK 350 1 0 0 0 0 0 0
3 2015 2 Ca 0 0 159703 2 36131 5 0 0
4 2015 2 Ch 88289 1 11227345 3 4305786 2 0 0
5 2015 2 Fu 0 0 794601 1 0 0 0 0
6 2015 2 Zu 0 0 70818 1 218310 9 0 0
7 2015 3 Ca 0 0 93577 1 9586 3 0 0
8 2015 3 Ch 0 0 11114302 3 1149480 4 0 0
9 2015 3 Fu 0 0 847562 1 0 0 0 0
10 2015 3 Zu 0 0 229086 2 0 1 0 0
11 2015 4 Ca 0 0 59999 1 9375 3 0 0
12 2015 4 Ch 0 0 9927702 3 16706470 8 0 0
13 2015 4 Fu 0 0 1000049 1 84655 2 0 0
14 2015 4 Zu 0 0 173894 1 74300 2 0 0
另外,这里是原始数据
year,month,company,wp,wn,ep,en,pa,pan,npa,npan
2015,1,Ch,6497985,1,1471586,2,4833118,3,0,0
2015,1,SK,350,1,0,0,0,0,0,0
2015,2,Ca,0,0,159703,2,36131,5,0,0
2015,2,Ch,88289,1,11227345,3,4305786,2,0,0
2015,2,Fu,0,0,794601,1,0,0,0,0
2015,2,Zu,0,0,70818,1,218310,9,0,0
2015,3,Ca,0,0,93577,1,9586,3,0,0
2015,3,Ch,0,0,11114302,3,1149480,4,0,0
2015,3,Fu,0,0,847562,1,0,0,0,0
2015,3,Zu,0,0,229086,2,0,1,0,0
2015,4,Ca,0,0,59999,1,9375,3,0,0
2015,4,Ch,0,0,9927702,3,16706470,8,0,0
2015,4,Fu,0,0,1000049,1,84655,2,0,0
2015,4,Zu,0,0,173894,1,74300,2,0,0
我想显示 (test$ep) 按 年和月 (xaxis) 排序的图,并且该图包含所有公司。 已解决 以后可能其他用户有类似的问题。下面我post我的方法。
test$year <- as.Date(test$year)
time_series <- xts(test$ep, order.by = test$year)
dygraph(time_series , group = test$company)
然而,情节并没有显示任何东西。
我的解决方法:
test$year <- as.yearmon(test$year , "%m %Y)
testre <- dcast(test, year~company ,value.var = "ep")
testre[is.na(testre)] <- 0
test_xts <- xts(testre[,-1], order.by = testre$year)
dygraph(test_xts)
非常感谢。
感谢这个平台,让我可以向其他好心的用户提问并学习很多东西。
这里有一些可以帮助您入门的东西。假设 test
是您的数据框,您应该首先(像您一样)从长转换为宽。一旦你闪亮的应用程序 运行,select 在你的 DT
table 中有几行。
library(dygraphs)
library(xts)
library(reshape2)
library(dplyr)
library(zoo)
library(shiny)
ui = fluidPage(
DT::dataTableOutput("x6"),
tags$br(),
tags$br(),
dygraphOutput("dygraph")
)
server = function(input, output) {
output$x6 <- DT::renderDataTable(DT::datatable({
test
}))
output$dygraph <- renderDygraph({
test_select <- test %>% select(year, month, company, ep)
test_select <- test_select[c(input$x6_rows_selected), ]
test_select_wide <- dcast(test_select, year + month ~ company, value.var="ep")
test_select_wide$Date <- as.yearmon(paste(test_select_wide$year, test_select_wide$month, sep = "-"))
test_select_wide$Date <- as.Date(test_select_wide$Date)
test_select_wide$year <- NULL
test_select_wide$month <- NULL
#test_select_wide <- test_select_wide[,c(6,1,2,3,4,5)]
test_select_wide_xts <- xts(test_select_wide[,-ncol(test_select_wide)], order.by=test_select_wide[,ncol(test_select_wide)])
dygraph(test_select_wide_xts)
})
}
shinyApp(ui=ui, server=server)
这是我的第一个问题。 Here is the graph. Why my graph does not show numbers on each lines and how can I change left side axis to display numbers rather than exponential sign
此外,我还有一些关于DT、dygraphs和shiny的问题。
1. 我已经在 R 中读取了我的 csv 数据,并且只是 运行 dygraphs 作为附加图像。但是,如果我希望我的图像在鼠标停留在其上时在线条上有一些数字,我该怎么做? 已解决
2. 另外,我想更改 y 轴以显示数字而不是指数符号。 已解决
3. 我有一个关于使用 shiny 来显示我的 excel 数据的想法。因此,我使用具有数据表功能的 DT 包。此外,我如何在 shiny 中组合 DT 和 dygraphs。我的意思是当我单击数据表和 select 某些行或列时,将显示动态折线图。也许还有其他有用和方便的软件包?
4. shiny与DT.
以下是我对 R 的 test.csv 数据输入。
year month company wp wn ep en pa pan npa npan
1 2015 1 Ch 6497985 1 1471586 2 4833118 3 0 0
2 2015 1 SK 350 1 0 0 0 0 0 0
3 2015 2 Ca 0 0 159703 2 36131 5 0 0
4 2015 2 Ch 88289 1 11227345 3 4305786 2 0 0
5 2015 2 Fu 0 0 794601 1 0 0 0 0
6 2015 2 Zu 0 0 70818 1 218310 9 0 0
7 2015 3 Ca 0 0 93577 1 9586 3 0 0
8 2015 3 Ch 0 0 11114302 3 1149480 4 0 0
9 2015 3 Fu 0 0 847562 1 0 0 0 0
10 2015 3 Zu 0 0 229086 2 0 1 0 0
11 2015 4 Ca 0 0 59999 1 9375 3 0 0
12 2015 4 Ch 0 0 9927702 3 16706470 8 0 0
13 2015 4 Fu 0 0 1000049 1 84655 2 0 0
14 2015 4 Zu 0 0 173894 1 74300 2 0 0
另外,这里是原始数据
year,month,company,wp,wn,ep,en,pa,pan,npa,npan
2015,1,Ch,6497985,1,1471586,2,4833118,3,0,0
2015,1,SK,350,1,0,0,0,0,0,0
2015,2,Ca,0,0,159703,2,36131,5,0,0
2015,2,Ch,88289,1,11227345,3,4305786,2,0,0
2015,2,Fu,0,0,794601,1,0,0,0,0
2015,2,Zu,0,0,70818,1,218310,9,0,0
2015,3,Ca,0,0,93577,1,9586,3,0,0
2015,3,Ch,0,0,11114302,3,1149480,4,0,0
2015,3,Fu,0,0,847562,1,0,0,0,0
2015,3,Zu,0,0,229086,2,0,1,0,0
2015,4,Ca,0,0,59999,1,9375,3,0,0
2015,4,Ch,0,0,9927702,3,16706470,8,0,0
2015,4,Fu,0,0,1000049,1,84655,2,0,0
2015,4,Zu,0,0,173894,1,74300,2,0,0
我想显示 (test$ep) 按 年和月 (xaxis) 排序的图,并且该图包含所有公司。 已解决 以后可能其他用户有类似的问题。下面我post我的方法。
test$year <- as.Date(test$year)
time_series <- xts(test$ep, order.by = test$year)
dygraph(time_series , group = test$company)
然而,情节并没有显示任何东西。
我的解决方法:
test$year <- as.yearmon(test$year , "%m %Y)
testre <- dcast(test, year~company ,value.var = "ep")
testre[is.na(testre)] <- 0
test_xts <- xts(testre[,-1], order.by = testre$year)
dygraph(test_xts)
非常感谢。
感谢这个平台,让我可以向其他好心的用户提问并学习很多东西。
这里有一些可以帮助您入门的东西。假设 test
是您的数据框,您应该首先(像您一样)从长转换为宽。一旦你闪亮的应用程序 运行,select 在你的 DT
table 中有几行。
library(dygraphs)
library(xts)
library(reshape2)
library(dplyr)
library(zoo)
library(shiny)
ui = fluidPage(
DT::dataTableOutput("x6"),
tags$br(),
tags$br(),
dygraphOutput("dygraph")
)
server = function(input, output) {
output$x6 <- DT::renderDataTable(DT::datatable({
test
}))
output$dygraph <- renderDygraph({
test_select <- test %>% select(year, month, company, ep)
test_select <- test_select[c(input$x6_rows_selected), ]
test_select_wide <- dcast(test_select, year + month ~ company, value.var="ep")
test_select_wide$Date <- as.yearmon(paste(test_select_wide$year, test_select_wide$month, sep = "-"))
test_select_wide$Date <- as.Date(test_select_wide$Date)
test_select_wide$year <- NULL
test_select_wide$month <- NULL
#test_select_wide <- test_select_wide[,c(6,1,2,3,4,5)]
test_select_wide_xts <- xts(test_select_wide[,-ncol(test_select_wide)], order.by=test_select_wide[,ncol(test_select_wide)])
dygraph(test_select_wide_xts)
})
}
shinyApp(ui=ui, server=server)