【发布时间】:2016-07-20 23:56:21
【问题描述】:
我正在尝试创建能够显示交互式绘图标题的闪亮应用程序(取决于 x 轴的选择值)
非常简单的例子:
library(shiny)
library(DT)
library(ggplot2)
x <- as.numeric(1:1000000)
y <- as.numeric(1:1000000)
z <- as.numeric(1:1000000)
data <- data.frame(x,y, z)
shinyApp(
ui = fluidPage(selectInput(inputId = "yaxis",
label = "Y-axis",
choices = list("x","y","z"),
selected = c("x")),
dataTableOutput('tableId'),
plotOutput('plot1')),
server = function(input, output) {
output$tableId = renderDataTable({
datatable(data, options = list(pageLength = 10, lengthMenu=c(10,20,30)))
})
output$plot1 = renderPlot({
filtered_data <- data[input$tableId_rows_all, ]
ggplot(data=filtered_data, aes_string(x="x",y=input$yaxis)) + geom_line()
})
}
)
我试过这段代码:
ggtitle("Line plot of x vs",input$yaxis)
它不工作,情节没有显示,给我一个错误:
Warning: Error in ggtitle: unused argument (input$yaxis)
[重要]
使用ggtitle(input$yaxis) 给了我一个交互式标题,但是我需要建立一个句子(如:x vs 的线图 input$yaxis),其中反应参数(input$yaxis ) 是其中的一部分!
感谢您的帮助!
干杯
【问题讨论】:
-
使用
ggtitle(paste("Line plot of x vs", input$yaxis))? -
为什么投反对票?也许这个问题看起来很简单,但 S.O.是帮助人,包括新人。 OP 很好地解释了问题并对其进行了格式化。他/她显然在提出问题之前付出了一些努力。