2017-11-27 7 views
0

ここに私のサンプルデータがあります。私のページに反応性のあるプロットを表示するために光沢のあるアプリを書こうと思っていますが、問題があります。棒チャートのX軸がRshinyで更新されない

enter image description here

そして、私の質問は、私は棒グラフで、x軸を選択すると、光沢のある上のプロットは更新されませんですが、y軸は問題であるとどのようにどこので、私は知りません更新することができますこの問題を解決します?

enter image description here

ui.R

library(shiny) 
library(dplyr) 
library(ggplot2) 

#Data Input# 
Sample <- read.table("D:/Sample.csv", sep = ",", header = T) %>% 
    subset(., select = c(2, 3, 4, 5, 6)) 

#Data Manipulation# 
Sample[, c(3:5)] <- sapply(Sample[, c(3:5)], as.factor) 
Catego.x <- colnames(Sample[, 3:5]) 
Catego.y <- colnames(Sample[, 3:5]) 
Conti <- colnames(Sample[, 1:2]) 

#ui.R# 
shinyUI(navbarPage(
    "Recommendation System", 
    navbarMenu(
    "Plot", 
    tabPanel("Boxplot", 
      sidebarPanel(
       selectInput(inputId = "Conti", 
          label = "Continuous Variables:", 
          choices = Conti), 
       selectInput(inputId = "Catego.x", 
          label = "Categories Variables:", 
          choices = Catego.x) 
      ), 
      mainPanel(
       plotOutput("boxplot") 
      )), 
    tabPanel("Barchart", 
      sidebarPanel(
       selectInput(inputId = "Catego.x", 
          label = "Categories Variables.x:", 
          choices = Catego.x), 
       selectInput(inputId = "Catego.y", 
          label = "Categories Variables.y:", 
          choices = Catego.y) 
      ), 
      mainPanel(
       plotOutput("barchart") 
      )) 
) 
)) 

server.R

library(shiny) 

#Data Input# 
Sample <- read.table("D:/Sample.csv", sep = ",", header = T) %>% 
    subset(., select = c(2, 3, 4, 5, 6)) 

#Data Manipulation# 
Sample[, c(3:5)] <- sapply(Sample[, c(3:5)], as.factor) 
Catego.x <- colnames(Sample[, 3:5]) 
Catego.y <- colnames(Sample[, 3:5]) 
Conti <- colnames(Sample[, 1:2]) 

#server.R# 
shinyServer(function(input, output){ 
    output$boxplot <- renderPlot({ 
    ggplot(data = Sample, aes_string(x = input$Catego.x, y = input$Conti, group = input$Catego.x)) + 
     geom_boxplot() 
    }) 
    output$barchart <- renderPlot({ 
    ggplot(data = Sample, aes_string(x = input$Catego.x, y = input$Catego.y, fill = input$Catego.y)) + 
     geom_bar(stat = "identity") 
    }) 
}) 
+0

データのdput()を投稿できますか?それ以外の場合は、問題を再現できません – Barbara

答えて

0

私の推測では、原因となっている問題がeventHandlerであるということです。

UIにactionButton、サーバー部分にeventHandlerを追加する必要があります。

UI:

shinyUI(navbarPage(
    "Recommendation System", 
    navbarMenu(
    "Plot", 
    tabPanel("Boxplot", 
      sidebarPanel(
       selectInput(inputId = "Conti", 
          label = "Continuous Variables:", 
          choices = Conti), 
       selectInput(inputId = "Catego.x", 
          label = "Categories Variables:", 
          choices = Catego.x) 
      ), 
      mainPanel(
       plotOutput("boxplot") 
      )), 
    tabPanel("Barchart", 
      sidebarPanel(
       selectInput(inputId = "Catego.x", 
          label = "Categories Variables.x:", 
          choices = Catego.x), 
       selectInput(inputId = "Catego.y", 
          label = "Categories Variables.y:", 
          choices = Catego.y), 
actionButton(
      inputId = "submit_loc", 
      label = "Submit"), 
      ), 
      mainPanel(
       plotOutput("barchart") 
      )) 
) 
)) 

サーバー:

shinyServer(function(input, output){ 
    observeEvent(
    eventExpr = input$submit_loc, 
    handlerExpr = 
    { 
    output$boxplot <- renderPlot({ 
    ggplot(data = Sample, aes_string(x = input$Catego.x, y = input$Conti, group = input$Catego.x)) + 
     geom_boxplot() 
    }) 
    output$barchart <- renderPlot({ 
    ggplot(data = Sample, aes_string(x = input$Catego.x, y = input$Catego.y, fill = input$Catego.y)) + 
     geom_bar(stat = "identity") 
    }) 
}) 
}) 

これを試してみて、私に知らせてください。

+0

私はすでに試してみましたが、うまくいきません。 – Yeh

+0

データフレームの 'dput()'を実行できますか? – Barbara

関連する問題