R闪亮互动情节标题为ggplot

Mal*_*l_a 0 r ggplot2 shiny

我正在尝试创建能够显示交互式绘图标题的Shiny App(取决于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()  
    })
  }
)  
Run Code Online (Sandbox Code Playgroud)

我试过这段代码:

ggtitle("Line plot of x vs",input$yaxis)
Run Code Online (Sandbox Code Playgroud)

它没有工作,情节没有显示,给我一个错误:

Warning: Error in ggtitle: unused argument (input$yaxis)
Run Code Online (Sandbox Code Playgroud)

[重要]

使用ggtitle(input$yaxis)给我一个交互式标题,但我需要建立一个句子(如:x vs的线图 input$yaxis),其中反应参数(input$yaxis)是它的一部分!

谢谢你的帮助!

干杯

Dev*_*auP 5

更改:

ggtitle("Line plot of x vs",input$yaxis)
Run Code Online (Sandbox Code Playgroud)

ggtitle(paste("Line plot of x vs",input$yaxis))
Run Code Online (Sandbox Code Playgroud)

正如错误所示,你有太多的参数传递给ggtitle函数,paste将从你的两个输入中创建一个单独的字符,中间有一个空格.你可以改变两者之间的分离sep =.