Bonjour a tous
je debute sous Rshiny et ma premiere app ne se passe pas comme il faut.

j ai cree un fichier sous RStudio qui fonctionne correctement. J aimerais utiliser RShiny pour donner la possibilite de choisir entre 3 graphique differents (representant 3 valeures issue du fichier R).

Le fichier R n est pas montre dans le programme ci joint mais sachez que ca fonctionne correctement et que j arrive a afficher les 3 graphiques (un a un).

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
library(shiny)
 
# Define UI for application that draws a histogram
shinyUI <-(fluidPage(
 
    # Application title
    titlePanel("Count of RFE Note/Email/SR per quarter and per Agent"),
    sidebarLayout(
            sidebarPanel(
                # Radio button for the choice
                radioButtons("Choice","Your choice:",choices = list("Note"="n","Email"="e","SR"="s"))
                        ),
 
            # Show a plot of the generated distribution
            mainPanel(
                plotOutput("graph")
                    )
                )
))
et voici la partie Server
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
library(shiny)
 
# Define server logic required to draw a histogram
shinyServer <-
(function(input, output) 
{
 
--- ici intervient mon fichier R qui fonctionne correctement----
 
      output$graph <- renderPlot 
      ({ 
        Choice <- reactive({rexp(input$Choice)})
        if (as_tibble(Choice()) == "n")
        { 
          ggplot (CountNotePerAgentdf, aes(x=YandQ, y=Count))+
          geom_bar(stat="identity",position="dodge",fill='#3333FF', width =.4 )+ # identity means that both x and y values are from the dataframe
          facet_grid(.~ Agent)+
          labs (title = "Number of SHR Note by Agent and by Quarter", x = "Year and Quarter", y = "Count of SHR Note")+ # to show the title
          theme(axis.text.x = element_text(angle=45)) # to incline the labels at 45 degrees 
        }  
        if (as_tibble(Choice()) == "e")
        {
          ggplot (CountEmailPerAgentdf, aes(x=YandQ, y=Count))+
          geom_bar(stat="identity",position="dodge",fill='#3333FF', width =.4 )+ # identity means that both x and y values are from the dataframe
          facet_grid(.~ Agent)+
          labs (title = "Number of SHR Email by Agent and by Quarter", x = "Year and Quarter", y = "Count of SHR Email")+ # to show the title
          theme(axis.text.x = element_text(angle=45)) # to incline the labels at 45 degrees  
        }
        if (as_tibble(Choice())== "s")
        {
          ggplot (CountSRPerAgentdf, aes(x=YandQ, y=Count))+
          geom_bar(stat="identity",position="dodge",fill='#3333FF', width =.4 )+ # identity means that both x and y values are from the dataframe
          facet_grid(.~ Agent)+
          labs (title = "Number of SHR SR by Agent and by Quarter", x = "Year and Quarter", y = "Count of SHR SR")+ # to show the title
          theme(axis.text.x = element_text(angle=45)) # to incline the labels at 45 degrees 
        }
 
      })
Mon radio button s affiche correctement mais disparait au bout de qq secondes et j ai le message suivant:

Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
Warning: Error in exprToFunction: argument "expr" is missing, with no default


Je comprend que ma variable Input n est pas reactive mais je ne sait pas quoi faire.
Votre aide serait precieuse...
Merci a tous