라이브러리 (RJSONIO)를 사용하여 BLS 데이터를 가져 오려고합니다. 가져온 데이터는 데이터 프레임에 있으며 ggplot을 사용하여 그릴 수 있습니다.BLS API를 사용하는 Shiny Apps
코드를 반짝이는 앱으로 변환 할 수 없습니다.
안내해주세요.
Server.R
library(shiny)
library(RCurl)
library(RJSONIO)
library(ggplot2)
bls.content <- getURLContent("http://api.bls.gov/publicAPI/v1/timeseries/data/CES6056132001")
bls.json <- fromJSON(bls.content, simplify=TRUE)
tmp <-bls.json$Results[[1]][[1]]
bls.df <- data.frame(year=sapply(tmp$data,"[[","year"),
period=sapply(tmp$data,"[[","period"),
periodName=sapply(tmp$data,"[[","periodName"),
value=as.numeric(sapply(tmp$data,"[[","value")),
stringsAsFactors=FALSE)
bls.df[bls.df$periodName!="Annual", ]
shinyServer(function(input, output) {
output$displot <- reactiveplot({
ggplot(data=bls.df, aes(x=year, y=value, group=period)),
gg <- ggplot(data=bls.df, aes(x=year, y=value, group=period)),
gg <- gg + geom_bar(stat="identity", position="dodge", aes(fill=period)),
gg
})
})
** UI.R **
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("BLS data"),
sidebarPanel(
selectInput("dataset", "Commodity:",
))),
mainPanel(
h3(textOutput("commSelected")),
verbatimTextOutput("CommodityTable"),
plotOutput("CommodityPlot")
))
어떤 반짝이 버전을 사용하십니까? Shiny의 지난 몇 버전에서 플롯을 생성하는 함수는'renderPlot'입니다. Shiny를 업데이트하면됩니다. –
Shiny Server 최신 버전 버전 0.98.693을 사용하고 있습니다. – user2733412