【发布时间】:2018-12-04 19:53:25
【问题描述】:
R/Shiny 新手,我似乎在生成简单的折线图时遇到了一些麻烦。
我试图通过用户输入显示每个图表,但我似乎无法让简单的折线图正常工作。
head(futures_data)
Corn Wheat Soybeans
2001-01-02 -0.019417476 -0.011627907 -0.009009009
2001-01-03 0.012101210 0.025339367 0.004545455
2001-01-04 0.000000000 0.003530450 -0.010055304
2001-01-05 -0.017391304 -0.004397537 -0.005586592
2001-01-08 -0.001106195 0.000000000 0.003064351
2001-01-09 0.007751938 0.007067138 0.008655804
rownames(futures_data) 给出每行数据的日期。
server.R
library(shiny)
library(googleVis)
server <- function(input, output){
futures <- as.data.frame(futures_data)
fut <- cbind.data.frame(x=futures$Corn, y=rownames(futures))
output$abc <- renderText({ "sjdaflkjsd" })
output$g1 <- renderPlot({
gvisLineChart(
data=fut
,xvar="x"
,yvar="y"
)
})
output$t1 <- renderTable({ head(futures) })
}
当使用output$g1 <- renderGvis({}) 时,表格也会消失。
ui.R
library(shiny)
library(googleVis)
ui <- fluidPage(
titlePanel("ShinyProj")
,sidebarLayout(
mainPanel(
,plotOutput("g1")
,tableOutput("t1")
)
,sidebarPanel(
radioButtons("typeInput"
,"Product Type"
,choices=c("Corn","Wheat","Soybeans")
,selected=("Corn")
)
)
)
我的问题是我做错了什么?
在此先感谢,欢迎任何其他批评
【问题讨论】: