首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >闪亮的应用程序没有渲染Dimple.js人口金字塔

闪亮的应用程序没有渲染Dimple.js人口金字塔
EN

Stack Overflow用户
提问于 2015-03-22 21:46:15
回答 1查看 183关注 0票数 0

我试图创建一个闪亮的应用程序,它通过选择/下拉输入来呈现给定年份的人口金字塔。我的ui.R代码是这样的:

代码语言:javascript
运行
复制
    library(shiny)

# Define UI for application that draws a outcome pyramid
shinyUI(fluidPage(

  # Application title
  titlePanel("Outcome Pyramid"),

  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "startyr",
                  label = "Select Start Year",
                  c(2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014)) 
    ),

    # Show a plot of the generated pyramid
    mainPanel(
      plotOutput("distPlot")
    )
  )
))

我的服务器看起来:

代码语言:javascript
运行
复制
library(shiny)
library(rCharts)

df <- read.csv("path_to_csv\data2.csv")

# Define server logic required to draw a population pyramid
shinyServer(function(input, output) {

  # Expression that generates a pypramid plot. The expression is
  # wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should re-execute automatically
  #     when inputs change
  #  2) Its output type is a plot

    output$distPlot <- renderPlot({

      startyear <- as.numeric(input$startyr)
      # Both arguments currently for the same thing, startyear, but eventually will want to 
      # process a range of years
      dPyramid(startyear, startyear) 

    })
})

getData <- function(startyr,endyear) {
  df <- subset(df,(year >= startyr & year <= endyear))
  return(df)
}

# DimpleJS pyramid

dPyramid <- function(startyear, endyear, colors=NULL) {
  dat <- getData(startyear, endyear)
  dat$n <- ifelse(dat$sex == 'MAL', -1 * dat$n, 1 * dat$n)
  dat$gencode <- ifelse(dat$sex == 'MAL', 1, 2)

  d1 <- dPlot(
    x = "n", 
    y = "agegrp", 
    groups = "sex", 
    data = dat, 
    type = 'bar')


  d1$yAxis(type = "addCategoryAxis", orderRule = "ord")
  d1$xAxis(type = "addMeasureAxis")
  d1$legend( x = 60, y = 10, width = 700, height = 20, horizontalAlign = "right")

  if (!is.null(colors)){
    d1$colorAxis(
      type = "addColorAxis", 
      colorSeries = "gencode", 
      palette = colors
    )
  }
  if (endyear - startyear >= 1) {
    d1$set(storyboard = "year")
    max_x <- round_any(max(dat$n), 1000, f = ceiling)
    min_x <- round_any(min(dat$n), 1000, f = floor)
    d1$xAxis(overrideMax = max_x, overrideMin = min_x)
  }

  if (max(dat$n >= 1000000)) {
    d1$setTemplate( afterScript = 
                      "
                    <script>
                    x._getFormat = function () {
                    return function(d) {
                    return d3.format(',.1f')(Math.abs(d) / 1000000) + 'm';
                    };
                    };
                    myChart.draw()
                    </script>
                    ")
  } else {
    d1$setTemplate( afterScript = 
                      "
                    <script>
                    x._getFormat = function () {
                    return function(d) {
                    return d3.format(',.0f')(Math.abs(d) / 1000) + 'k';
                    };
                    };
                    myChart.draw()
                    </script>
                    ")
  }

  d1
}

然而,每当我运行这个应用程序,任何东西都不会呈现在闪亮的应用页面上。这里使用的csv可以在这里找到https://github.com/kilimba/data

Tumaini,感谢你对这件事的关注。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-23 09:11:00

经过大量的修改和研究,我发现我需要使用showOutput("distPlot", "dimple")而不是plotOutput("distPlot"),使用renderChart2()而不是renderPlot()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29200233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档