r - 鼠标悬停在 plotly 和 Shiny

标签 r shiny rstudio plotly

我有一些巧妙的代码,可以在鼠标悬停时在 RStudio 和 RPubs 上完美地调用数据帧的行名称。 . .但嵌入到 Shiny 中时则不然。
基本代码是:

require(shiny)
require(plotly)
Trial <- read.table("http://history.emory.edu/RAVINA/Aozora/Data/Trial.txt", row.names = 1)
plot_ly(Trial, x=V1, y=V2, text=rownames(Trial), mode = "markers") 

然而,Shiny 版本完全死了。我错过了什么?
require(shiny)
require(plotly)
Trial <- read.table("http://history.emory.edu/RAVINA/Aozora/Data/Trial.txt", row.names = 1)

ui <- fluidPage(
  titlePanel("Word Frequency Analysis for Meiji-era Authors"),
      mainPanel(
      plotOutput("plot"),
      dataTableOutput("Print")
    )
  )


server <- function(input, output){


  output$plot<-renderPlot({
    p <- plot_ly(Trial, x=V1, y=V2, text=rownames(Trial), mode = "text")
    plot(p)
  })
  output$Print<-renderDataTable({Trial})



}

shinyApp(ui = ui, server = server)

最佳答案

您需要为它们的对应函数替换一些基本的 Shiny 函数。即plotOutput -> plotlyOutputrenderPlot -> renderPlotly .还有,最后一个 plot(p)不是你想返回的:你只想返回p (绘图对象)。

require(shiny)
require(plotly)
Trial <- read.table("http://history.emory.edu/RAVINA/Aozora/Data/Trial.txt", row.names = 1)

ui <- fluidPage(
  titlePanel("Word Frequency Analysis for Meiji-era Authors"),
  mainPanel(
    plotlyOutput("plot"),
    dataTableOutput("Print")
  )
)


server <- function(input, output){            
  output$plot<-renderPlotly({
    p <- plot_ly(Trial, x=V1, y=V2, text=rownames(Trial), mode = "text")
    #plot(p)
    p
  })
  output$Print<-renderDataTable({Trial})     
}

shinyApp(ui = ui, server = server)

关于r - 鼠标悬停在 plotly 和 Shiny ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34031570/

相关文章:

R Shiny - 如果两个输入具有相同的值,如何显示反馈消息(使用shinyFeedback)

sql-server - 与 SQL Server(和 Sybase 12.5)的 DBI 连接不返回希腊字符

r - 无法在 RStudio 中启动 SparkR

debugging - 无法退出调试/浏览器模式

R函数创建和保存图形

r - 如何使用ggplot在x轴上只显示年份

r - 使用 spTransform 将 SpatialPolygonsDataFrame 转换为投影坐标

r - deparse(substitute()) 正常返回函数名,但在 for 循环内部调用时返回函数代码

r - 使用 includeHTML 时 sidebarMenu 无法正常工作

python - 如何在 python 的 uvinicorn 上运行的 py-shiny 中设置回溯日志记录?