繁体   English   中英

带有DT和闪亮效果的R字形图

[英]R - dygraphs with DT and shiny

这是我的第一个问题。 这是图。 为什么我的图形未在每行上显示数字,以及如何更改左侧轴以显示数字而不是指数符号

另外,我对DT书本光泽有一些疑问。
1.我已经在R中读取了我的csv数据,并简单地将字形图作为附加图像。 但是,如果希望我的图像在鼠标停留在行上时有一些数字,该怎么办? 解决了
2.另外,我想将y轴更改为显示数字而不是指数符号。 解决了
3.我有一个关于使用Shiny来显示我的excel数据的想法。 因此,我将DT包与datatable函数一起使用。 而且,如何将DT书本结合起来发亮 我的意思是,当我单击数据表并选择一些行或列时,将显示动态折线图。 也许还有其他有用且方便的软件包?
4.在哪里可以找到有关与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

我想显示按年和月(xaxis)排序的图表(test $ ep ,该图表包含所有公司。 解决了将来其他用户可能也有类似的问题。 我在下面发布自己的方式。

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是您的数据帧,则应首先(与您一样)将长度从长转换为宽。 闪亮的应用程序运行后,在DT表中选择几行。

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM