鼠标悬停在阴谋和闪亮的

时间:2015-12-01 22:39:43

标签: 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") 
然而,闪亮的版本完全死了。我错过了什么?

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)

1 个答案:

答案 0 :(得分:8)

你需要为他们的情节对手换掉一些基本的闪亮功能。即plotOutput - &gt; plotlyOutputrenderPlot - &gt; 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)