【问题标题】:R - dygraphs with DT and shinyR - 带有 DT 和闪亮的 dygraphs
【发布时间】:2017-07-25 10:41:54
【问题描述】:

这是我的第一个问题。 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

此外,我还有一些关于 DTdygraphsshiny 的问题。
1. 我已经在 R 中读取了我的 csv 数据,只需运行 dygraphs 作为附加图像。但是,如果我希望我的图像在鼠标停留在图像上时有一些数字,我该怎么办? 已解决
2. 另外,我想更改 y 轴以显示数字而不是指数符号。 已解决
3. 我有个想法,用shiny来展示我的excel数据。因此,我使用带有数据表功能的 DT 包。此外,如何在 shiny 中结合 DTdygraphs。我的意思是当我单击数据表并选择一些行或列时,将显示动态折线图。也许还有其他有用且方便的软件包?
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

我想显示按年月(xaxis)排序的图(test$ep),图包含所有公司。 已解决也许其他用户以后会有类似的问题。我在下面发布我的方式。

test$year time_series dygraph(time_series , group = test$company)

然而,剧情并没有显示任何东西。

我的解决方法:

test$year testre testre[is.na(testre)] test_xts dygraph(test_xts)

非常感谢。
感谢这个平台,所以我可以向其他善良的用户提问并学习很多东西。

【问题讨论】:

  • 你能提供一个reproducible example吗?
  • @Samuel 好的。我编辑了我的问题。请帮我。非常感谢。

标签: r shiny dygraphs dt


【解决方案1】:

这里有一些东西可以帮助您入门。假设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)

【讨论】:

  • 谢谢你。但是,我遇到了一些麻烦。警告:
  • @Peter,我明白你的意思。我对我的答案做了一个小的编辑,但是这些(警告)错误是正常的,因为 is line: test_select_wide
猜你喜欢
  • 2016-12-18
  • 2016-01-02
  • 2020-02-03
  • 1970-01-01
  • 2016-10-25
  • 2020-09-18
  • 2017-03-06
  • 2015-06-30
  • 1970-01-01
相关资源
最近更新 更多