簡體   English   中英

R:密密麻麻的閃亮油條

[英]R: plotly and shiny barplot

我正在根據World Phones的示例進行繪圖

sidebarPanel不起作用,您能告訴我為什么嗎?

data <- data.frame(x=rep(c('A','B','C'), each = 1, times = 3),
                   y=runif(9, 5, 10),
                   group=rep(c('2011','2012','2013'), each = 1, times= 3))

ui.R:

library(shiny)
library(plotly)
# Define the overall UI
shinyUI(
# Use a fluid Bootstrap layout
fluidPage(    
# Give the page a title
titlePanel("Barchart"),
# Generate a row with a sidebar
sidebarLayout(      
# Define the sidebar with one input
sidebarPanel(
selectInput("letter", "Letter:", levels(data[,1])),
hr()),
# Create a spot for the barplot
mainPanel(
plotlyOutput("dataPlot")  
))))

server.R:

library(shiny)
library(plotly)
shinyServer(function(input, output) {
# Fill in the spot we created for a plot
output$dataPlot <- renderPlotly({
# Render a barplot
p <- plot_ly(data, x = input$letter, y=y, group=group,type = "bar")
p})
})

Batanicheck給出的每件事都是正確的,但對圖進行一些修改即可獲得准確的輸出。

更換

> p <- plot_ly(data[data$x==input$letter,], x=group, y=y,type = "bar")

WITH

> p <- plot_ly(data[data$x==input$letter,], x=x, y=y, group=group,type = "bar")

對我來說,它可以在瀏覽器以及Rstudio瀏覽器中使用...

我不能完全理解你所看到的

但是例如,如果您只想按年份繪制一個字母

1)你有不好的df為例- A只存在到2011年

2)我使用data <- data.frame(x=rep(c('A','B','C'), each = 1, times = 3), y=runif(9, 5, 10), group=rep(c('2011','2012','2013'), each = 3, times= 1))

3)試試p <- plot_ly(data[data$x==input$letter,], x=group, y=y,type = "bar")

不要忘記將data聲明到uiserver

並且僅在瀏覽器中工作,而不是在rstudion查看器中工作(對我來說)

暫無
暫無

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

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