0

Mes、Visitas、Pedidos の 3 つの列を持つデータ フレームがあります。

コード:

    structure(list(Mes = structure(1:12, .Label = c("Enero", "Febrero", 
"Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", 
"Octubre", "Noviembre", "Diciembre"), class = "factor"), Visitas = c(100L, 
200L, 300L, 400L, 500L, 600L, 700L, 800L, 900L, 1000L, 1100L, 
1200L), Pedidos = c(20L, 40L, 60L, 80L, 100L, 120L, 140L, 160L, 
180L, 200L, 220L, 240L)), .Names = c("Mes", "Visitas", "Pedidos"
), row.names = c(NA, -12L), class = "data.frame")

「checkboxGroupInput」からの選択に基づいて月を表示する光沢のあるアプリを実行しています。

私はこのチュートリアルに従っています: http://shiny.rstudio.com/gallery/datatables-demo.html。行に基づいてサブセットを実行していることを除いて(例のように、列ではなく「Mes」に対して)。

しかし、私はこのエラーが発生します:

Listening on http://127.0.0.1:7026
Error in mapply(ids, choices, names(choices), FUN = function(id, value,  : 
  zero-length inputs cannot be mixed with those of non-zero length

ui.R

library(shiny)
library(ggplot2)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

  # Application title
  titlePanel("Hello Shiny!"),

  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput('meses', 'Elige meses:',
                         names(OmarSessiones$Meses),
                         selected = names(OmarSessiones$Meses))
    ),

    # Show a plot of the generated distribution
    mainPanel(
      dataTableOutput('mytable1'))
    )
  )
)

サーバー.R

library(shiny)


OmarSessiones <- read.csv2("D:\\omarmeses.csv", 
                          header = T)







# Define server logic required to draw a histogram
shinyServer(function(input, output) {





    output$mytable1 <- renderDataTable({
      library(ggplot2)
      OmarSessiones[input$meses,]
    })




  # Expression that generates a histogram. The expression is
  # wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should re-execute automatically
  #     when inputs change
  #  2) Its output type is a plot


})
4

1 に答える 1

1

あなたはほとんどそこにいました。row.names()の代わりに使用する必要がありnames()ます。次に、データの行名をデータの最初の列に変更します。

library(shiny)
library(ggplot2)
OmarSessiones <- structure(list(Mes = structure(1:12, .Label = c("Enero", "Febrero", 
"Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", 
"Octubre", "Noviembre", "Diciembre"), class = "factor"), Visitas = c(100L, 
200L, 300L, 400L, 500L, 600L, 700L, 800L, 900L, 1000L, 1100L, 
1200L), Pedidos = c(20L, 40L, 60L, 80L, 100L, 120L, 140L, 160L, 
180L, 200L, 220L, 240L)), .Names = c("Mes", "Visitas", "Pedidos"
), row.names = c(NA, -12L), class = "data.frame")
# Change rownames
row.names(OmarSessiones) <- OmarSessiones$Mes
server <- function(input, output, session) {


     output$mytable1 <- renderDataTable({
      library(ggplot2)
      OmarSessiones[input$meses,]
    })


}

ui <- fluidPage(

     # Application title
  titlePanel("Hello Shiny!"),

  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput('meses', 'Elige meses:',
                         row.names(OmarSessiones),
                         selected = row.names(OmarSessiones))
    ),

    # Show a plot of the generated distribution
    mainPanel(
      dataTableOutput('mytable1'))
    )
    )


shinyApp(ui = ui, server = server)
于 2015-03-15T09:28:25.083 に答える