簡體   English   中英

plotly如何在R shiny中使用

[英]How to use plotly in R shiny

我正在嘗試為我使用 shiny 生成的 output 添加圖形。圖形生成出現錯誤。 有人可以看看並提供幫助。 條形圖參數是從計算中生成的基於計算的輸出。

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

在此包的最新更新中,服務器端函數中沒有“renderplotly”參數,您會收到錯誤消息。 像這樣的東西

警告:renderPlotly 中的錯誤:找不到函數“renderPlotly”49:服務器 [#3]renderPlotly 中的錯誤({:找不到函數“renderPlotly”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM