R:阴谋和有光泽的条纹

时间:2015-12-18 11:55:11

标签: r shiny plotly

我根据plotly制作了一张带有World Phones example的条形图。

sidebarPanel不起作用,你能告诉我为什么吗?

.loudbutton:hover {
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

ui.R:

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

server.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")  
))))

2 个答案:

答案 0 :(得分:3)

Batanicheck给出的每一件事都是正确的,但对情节的一点修改可以得到你的确切输出。

替换

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

。通过

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

对我来说,它适用于浏览器以及Rstudio查看器......

答案 1 :(得分:1)

我完全不知道你想看到什么

但是例如,如果你想要多年只绘制一个字母

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 viewer(对我而言)