【问题标题】:R Shiny Interactive plot title for ggplotggplot 的 R Shiny Interactive 绘图标题
【发布时间】: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 很好地解释了问题并对其进行了格式化。他/她显然在提出问题之前付出了一些努力。

标签: r ggplot2 shiny


【解决方案1】:

变化:

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

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

正如错误所暗示的,您传递给ggtitle 函数的参数太多,paste 将在您的两个输入中创建一个字符,中间有一个空格。您可以使用sep = 改变两者之间的间隔。

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 2023-03-15
    • 2016-02-26
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 2021-12-27
    相关资源
    最近更新 更多