0
我想使用庫(RJSONIO)導入BLS數據。 導入的數據位於數據框中,我可以使用ggplot繪圖。關於使用BLS API的閃亮應用程序
我無法將代碼轉換爲閃亮的應用程序。
請指導我。
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