【问题标题】:How to use plotly in R shiny如何在 R 闪亮中使用 plotly
【发布时间】:2020-06-03 06:00:42
【问题描述】:

我正在尝试为我使用闪亮生成的输出添加图表。我在生成图形时遇到错误。有人可以看看并提供帮助。条形图参数是计算生成的基于计算的输出。

server
output$graph<- renderPlotly({

  plotly( x= c(as.numeric(input$contract), round(frateperton()), differencerate()),

         y= c('Contract Rate', 'ZBC Rate', 'Difference'),

         name = "Zero Based Rate Chart",

         type = "bar")

})


UI
plotlyOutput("graph"),

【问题讨论】:

    标签: r shiny shinydashboard shiny-server


    【解决方案1】:

    首先,对你的帖子有两点评论:

    • 它不可重现,请参阅 here 了解什么是可重现的示例以及如何制作
    • 显然您搜索的不够多。在任何搜索引擎中输入“r shiny plotly output”都会给出几种可能的解决方案(例如here)。

    下次遇到问题,请在 StackOverflow 上发帖前考虑这两点。

    现在,这是答案(使用 iris 数据,因为您的示例不可重现):

    library(shiny)
    library(plotly)
    
    ui <- fluidPage(
      selectInput("choice", "Choose", choices = names(iris), selected = NULL),
      plotlyOutput("graph")
      )
    
    server <- function(input, output, session){
    
      output$graph <- renderPlotly({
        plot_ly(iris, x = ~get(input$choice), y = ~Sepal.Length, type = 'scatter', mode = 'markers')
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • @mayank14:这个答案应该被标记为正确。
    猜你喜欢
    • 2020-09-30
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    相关资源
    最近更新 更多