2017-11-27 1 views
0

여기 내 샘플 데이터가 있습니다. 내 페이지에 반응 형 플롯을 표시하기 위해 반짝이는 앱을 쓰고 싶지만 그 중에 뭔가 잘못되었습니다. 내가 막대 차트에서 x 축을 선택하면 막 대형 차트의 X 축이 Rshiny에서 업데이트되지 않습니다

enter image description here

그리고 내 질문은 업데이트되지 않습니다 반짝에 플롯하지만, 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

관련 문제