Mar*_*k R 5 r rstudio shiny 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")
Run Code Online (Sandbox Code Playgroud)
然而,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)
Run Code Online (Sandbox Code Playgroud)
你需要为他们的情节对手换掉一些基本的闪亮功能.即plotOutput- > plotlyOutput和renderPlot- > 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1029 次 |
| 最近记录: |