如何在 R 中使用 plotly

may*_*k14 3 r shiny shiny-server shinydashboard

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

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"),

Run Code Online (Sandbox Code Playgroud)

bre*_*auv 14

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

  • 它不可重现,请参阅此处了解可重现示例是什么以及如何制作示例
  • 显然你搜索的还不够多。在任何搜索引擎中输入“r Shiny plotly output”都会给出几个潜在的解决方案(例如这里)。

下次遇到问题,请考虑这两点,然后再在 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)
Run Code Online (Sandbox Code Playgroud)

  • @mayank14:这个答案应该被标记为正确。 (4认同)