2016-04-01 75 views
-2

我想創建閃亮應用,其能夠顯示交互式情節標題(依賴於x軸已選定值)ř閃亮交互式情節標題ggplot

非常簡單的例子:

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的支線劇情VSinput$yaxis),其中反應參數(input$yaxis )是它的一部分!

感謝您的幫助!

乾杯

+2

使用'ggtitle(粘貼(「x線條圖」,輸入$ yaxis))'? – Axeman

回答

4

變化:

ggtitle("Line plot of x vs",input$yaxis) 

ggtitle(paste("Line plot of x vs",input$yaxis)) 

由於錯誤提示,你有太多的參數傳遞給ggtitle功能,paste將創建一個單個字符出你的兩個輸入,它們之間有一個空格。您可以使用sep =更改兩者之間的分隔。