2016-01-21 15 views
5

पर निर्भर है मेरे पास नीचे कुछ डेटा है जिसका उपयोग मैं आर चमक में डोनट चार्ट बनाने के लिए कर रहा हूं, जहां date एक वर्ण है। मैं उस ईमेल का चयन करने में सक्षम होना चाहता हूं जिसका स्कोर मैं देखना चाहता हूं, लेकिन फिर दूसरे ड्रॉपडाउन चयन में केवल उन तिथियों को देखें जिनके लिए उस ईमेल में गतिविधि है।आर चमकदार selectInput जो किसी अन्य selectInput

उदाहरण के लिए, यदि मैं पहले ड्रॉपडाउन में ईमेल = xxxx का चयन करता हूं, तो मैं दिनांक चयन फ़ील्ड में केवल 'कोई गतिविधि नहीं' देखना चाहता हूं। और ईमेल के लिए = yyyy, मैं चयन के रूप में केवल 6/17/14, 6/18/14, 6/19/14 देखना चाहता हूं।

मैंने UI में एक नेस्टेड सबसेटिंग की कोशिश की है। उदाहरण:

> ui <- shinyUI(fluidPage(
+ sidebarLayout(
+  sidebarPanel(
+  selectInput('Select', 'Customer:', choices = unique(as.character(dat5$email))), 
+  selectInput("User", "Date:", choices = dat5[dat5$email==input$Select,date]) 
+ ), 
+  mainPanel(plotOutput("distPlot")) 
+ ) 
+)) 

लेकिन यह अभी भी हर संभव तिथि चयन

से पता चलता आंकड़े

email date  variable value ymin ymax 
xxxx no activity e_score   0 0  0 
xxxx no activity diff   1 0  1 
yyyy 6/17/14  e_score 0.7472 0  0.7472 
yyyy 6/17/14  diff  0.2528 0.7472 1 
yyyy 6/18/14  e_score 0.373 0  0.373 
yyyy 6/18/14  diff  0.627 0.373 1 
yyyy 6/19/14  e_score 0.533 0  0.533 
yyyy 6/19/14  diff  0.467 0.533 1 

मेरे कोड अब तक:

app.R

library(shiny) 
library(shinydashboard) 

ui <- shinyUI(fluidPage(
    sidebarLayout(
    sidebarPanel(
     selectInput('Select', 'Customer:', choices = unique(as.character(dat5$email))), 
     selectInput("User", "Date:", choices = unique(dat5$date)) 
    ), 
    mainPanel(plotOutput("distPlot")) 
) 
)) 


server <- function(input, output) { 
    output$distPlot <- renderPlot({ 
    ggplot(data = subset(dat5, (email %in% input$Select & date %in% input$User)), aes(fill=variable, ymax = ymax, ymin = ymin, xmax = 4, xmin = 3)) + 
     geom_rect(colour = "grey30", show_guide = F) + 
     coord_polar(theta = "y") + 
     geom_text(aes(x = 0, y = 0,label = round(value[1]*100))) + 
     xlim(c(0, 4)) + 
     theme_bw() + 
     theme(panel.grid=element_blank()) + 
     theme(axis.text=element_blank()) + 
     theme(axis.ticks=element_blank()) + 
     xlab("") + 
     ylab("") + 
     scale_fill_manual(values=c('#33FF00','#CCCCCC')) 

    }) 
} 
    shinyApp(ui = ui, server = server) 

उत्तर

8

आप ऐप के ui.R भाग में इनपुट तक नहीं पहुंच सकते हैं, इसलिए आपको अपने चयन इनपुट को गतिशील रूप से उत्पन्न करने के लिए renderUi/uiOutput का उपयोग करने की आवश्यकता है।

अपने ui.R में आप जोड़ सकते हैं:

uiOutput("secondSelection") 

और अपने server.R में:

output$secondSelection <- renderUI({ 
       selectInput("User", "Date:", choices = as.character(dat5[dat5$email==input$Select,"date"])) 
     }) 
+0

कि यह किया !! किसी कारण से, मुझे 'विकल्प = as.character (डेटा 5 [डेटा 5 $ ईमेल == इनपुट $ चयन," दिनांक "] था)' तारीख के उद्धरण के बिना। अन्यथा महान काम किया! – Hillary

+0

मैं उत्तर कथन से उलझन में हूं "आप ऐप के ui.R भाग में इनपुट तक नहीं पहुंच सकते हैं"। जब आप सशर्त पैनल का उपयोग करते हैं तो आप input.panel के आधार पर स्थिति को परिभाषित कर रहे हैं। क्या यह यूआई के इनपुट के आधार पर नहीं है? –

संबंधित मुद्दे