【问题标题】:Interactivity with Shiny, rCharts and nvd3?与 Shiny、rCharts 和 nvd3 的交互性?
【发布时间】:2013-08-14 14:41:05
【问题描述】:

[编辑]

我一直在使用 nvd3 的 rcharts 包装器编写一个简单的基于 Shiny 的多条形图实现。当我从 R 控制台本地生成图形时,我能够与之交互,并且转换按预期工作。但是,当包裹在闪亮的界面中时,它不会重绘,也不允许与绘图本身进行交互。

我已经粘贴了我在下面使用的代码以及示例数据集。使用示例数据运行时,效果很好。但是,我的实际数据集要大得多(trips 数据集中有超过 5k 条记录,stations 数据集中有超过 100 个条目)。不知道为什么这很重要,但它似乎破坏了界面。

这里是 global.r 文件:

#global.r

preppedTrips <- read.csv("trips.csv")
stations <- read.csv("stations.csv")
stationnames <- as.character(stations$Name)

这里是 server.r 文件:

#ui.r 
require(rCharts)

shinyServer(function(input, output) { 

  trips <- reactive({
    preppedTrips[preppedTrips$station == stationID(),]
  })

  stationID <- reactive({
    a <- as.character(stations[stations$Name == input$station,]$ID)
  })

  output$caption <- renderText({
    paste("Station ID is: ", stationID(), sep="")
  })

  output$plot <- renderChart({  
    n1 <- nPlot(value ~ time, group="group", data = trips(), type="multiBarChart")
    n1$set(dom = "plot")
    return(n1)
  })
})

这是 ur.r 文件:

require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("nvd3 test"),

  sidebarPanel(
    selectInput(inputId = 'station',
      label = "Stations",
      choices = stationnames,
      selected = 's1'),

    submitButton("Update View")
  ),

  mainPanel(
    h3(textOutput("caption")), 

    showOutput("plot","nvd3")
  )
))

这是 trips.csv 文件的示例:

"","time","variable","value","group","station"
"8","07:00","V1",73,"Start","s1"
"9","08:00","V1",145,"Start","s1"
"10","09:00","V1",146,"Start","s1"
"11","10:00","V1",85,"Start","s1"
"12","11:00","V1",84,"Start","s1"
"13","12:00","V1",102,"Start","s1"
"14","13:00","V1",126,"Start","s1"
"32","07:00","V1",27,"End","s1"
"33","08:00","V1",97,"End","s1"
"34","09:00","V1",148,"End","s1"
"35","10:00","V1",70,"End","s1"
"36","11:00","V1",106,"End","s1"
"37","12:00","V1",84,"End","s1"
"38","13:00","V1",124,"End","s1"
"55","07:00","V1",24,"Start","s2"
"56","08:00","V1",107,"Start","s2"
"57","09:00","V1",127,"Start","s2"
"58","10:00","V1",54,"Start","s2"
"59","11:00","V1",50,"Start","s2"
"60","12:00","V1",59,"Start","s2"
"61","13:00","V1",45,"Start","s2"
"78","07:00","V1",34,"End","s2"
"79","08:00","V1",101,"End","s2"
"80","09:00","V1",95,"End","s2"
"81","10:00","V1",54,"End","s2"
"82","11:00","V1",44,"End","s2"
"83","12:00","V1",60,"End","s2"
"84","13:00","V1",56,"End","s2"

这里是stations.csv 文件的示例:

"","Name","ID"
"1","Station 1","s1"
"2","Station 2","s2"

【问题讨论】:

  • 请发布您的代码,以便我们检查。在没有代码的情况下,不可能说出可能出了什么问题。
  • 很抱歉。添加了 ui.r 和 server.r 代码。
  • 您能否也发布您的数据文件样本trips.csvstations.csv,以便您的示例可重现。
  • 完成。提前致谢。
  • 对不起,默认值selected的原始代码有错误。现已修复。

标签: r nvd3.js shiny rcharts


【解决方案1】:

好吧,我脸上的鸡蛋。 csv 文件最后一行中的一些错误数据破坏了构建。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 2019-01-30
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多