【问题标题】:Dynamically change graph title upon selection plot_ly选择 plot_ly 后动态更改图形标题
【发布时间】:2021-01-07 19:38:17
【问题描述】:

我的闪亮服务器中有以下代码:

  output$SimilarityComparison <- renderPlotly({
    df <- newmpresults[place == input$CitySelected & upc_code == input$SKUSelected & category == input$categoryselectedtrends,]
    graph.title <- df$description
    plot_ly(
      #newmpresults[place == input$CitySelected & upc_code == input$SKUSelected & category == input$categoryselectedtrends,],
      df,
      x=~quantity,
      y = ~unit_price,
      text = ~paste("Precio: ", unit_price, '$<br>Cantidad:', quantity, '<br>MP:', type),
      color = ~as.factor(type)) %>%
      add_markers()%>%
      layout(
        title = ~paste('Producto:', graph.title),
        xaxis = list(title ='Cantidad'),
        yaxis = list(title ='Precio')) %>%
      config(displayModeBar = FALSE)
  })

我希望在更改 UI 中的选择时,我的图表标题会更改并显示在图表中(只有 layout( title = ~paste('Producto:', graph.title) 部分给我带来了问题)。我认为这就像将df$description 声明为我的标题输入一样简单,但它没有显示在图表中。其他一切都很好。有什么建议可以给我吗?

【问题讨论】:

    标签: r plot shiny


    【解决方案1】:

    如果df$description 不是单个条目,则您有一个向量作为标题。试试这个

    graph.title <- unique(df$description)
    layout( title = paste('Producto:', graph.title)
    

    【讨论】:

    • 谢谢,我完全忘记了df$description 是一个向量。
    猜你喜欢
    • 1970-01-01
    • 2017-05-22
    • 2016-11-28
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    相关资源
    最近更新 更多