Few tabs and no plotOutput

.Hello all,
I wish to create shiny app with few tabs and I actually did it, however there are no plots on the tabs.
I read some articles to solve this problem, and I created different plots to be shown, but it didn't help. Plots are using information from the same data.table.

Could somebody look at this and tell me what and where is the problem?
Thanks in advance.

Data is generated from csv file.

ui1 <- fluidPage(navbarPage("Polish people", tabPanel('Climate change',
  
  pageWithSidebar(
  # Application title
  titlePanel("What do we think about climate change?"),

 sidebarPanel(
    selectInput("variable", "Question:",
                list("How often do you do things to reduce energy use?" = "rdcenr",
                     "How much electricity should be generated from coal?" = "elgcoal",
                     "How much electricity should be generated from natural gas?" = "elgngas",
                     "How much electricity should be generated from hydroelectric power?" = "elghydr",
                     "How much electricity should be generated from nuclear power?" = "elgnuc",
                     "How much electricity should be generated from solar power?" = "elgsun",
                     "How much electricity should be generated from wind?" = "elgwind",
                     "How much electricity should be generated from biomas?" = "elgbio",
                     "How much are you worried about power cuts?" = "wrpwrct",
                     "Do you think world's climate is changing?" = "clmchng",
                     "What is climate change caused by?" = "ccnthum",
                     "To what extent do you feel personal responsibility to reduce climate change?" = "ccrdprs",
                     "How are you worried about climate change?" = "wrclmch",
                     "Climate change has good or bad impact across world?" = "ccgdbd"),
            
                selected = "ccgdbd"),
    
    radioButtons("dist", "Distribution type:",
               c("Dodge" = "dodge",
                 "Fill" = "fill",
                 "Stack" = 'stack')),
    
    selectInput("var", "Variable2:",
                list("Gender" = 'gender',
                     "Age" = "age1",
                     "European Union" = "eu",
                     "Children" = "children"),
                selected = "eu")),
  
  mainPanel(
    h3(textOutput("caption")),
    plotOutput("MeTooPlot"))
 )
 ),
  
tabPanel('Life satisfaction',
         
         fluidRow(pageWithSidebar(titlePanel("Are polish people satisfied with their lives?"),
           sidebarPanel(
             selectInput("variable2", "Question:",
                         list("How satisfied are you with your life? " = "stflife",
                              "How satisfied are you with present state of the country's economy?" = "stfeco",
                              "How satisfied are you with government?" = "stfgov",
                              "How satisfied are you with the way democracy works in country?" = "stfdemo",
                              "How satisfied are you with the state of health service? " = "stfhlth",
                              "Men should have more right to job than women when jobs are scarce" = "mnrgtjb",
                              "How happy are you?" = "happy"),
                         selected = "stflife"),
             
             radioButtons("dist2", "Distribution type:",
                          c("Dodge" = "dodge",
                            "Fill" = "fill",
                            "Stack" = 'stack')),
             
             selectInput("var2", "Variable2:",
                         list("Gender" = 'gender',
                              "Age" = "age1",
                              "European Union" = "eu",
                              "Children" = "children"),
                         selected = "eu")),
           
           mainPanel(
             h3(textOutput("caption")),
             fluidRow(plotOutput("MeTooPlot2")))
         ))),
                         
tabPanel('Other',fluidRow(
         
         pageWithSidebar( mainPanel(
           plotOutput("MeTooPlot3")),
           # Application title
           titlePanel("What poles think?"),
           
           sidebarPanel(
                     selectInput("variable3", "Question:",
                         list("Watching, reading or listening to news about politics (in minutes)" = 'news',
                              "How often do you use Internet?" = "internet",
                              "Can you trust others?" = "trust",
                              "Are you interested in politics?" = "polintr",
                              "Which party did you vote last selection?" = "party",
                              "Men should have more right to job than women when jobs are scarce" = "mnrgtjb",
                              "Gays and lesbians free to live life as they wish" = "freehms",
                              "Immigration is good or bad for the economy" = "imbgeco",
                              "Countr's cultural life is undermined or enriched by immigrants?" = "imueclt",
                              "Immigrants make country worse or better place to live?" = "imwbcnt",
                              "How religious are you?" = "rlgdgr"),
                         
                         selected = "internet"),
             
             radioButtons("dist3", "Distribution type:",
                          c("Dodge" = "dodge",
                            "Fill" = "fill",
                            "Stack" = 'stack')),
             
             selectInput("var3", "Variable2:",
                         list("Gender" = 'gender',
                              "Age" = "age1",
                            "European Union" = "eu",
                              "Children" = "children"),
                         selected = "age1"))
          )
         
           )
         ))
)

server1 = function(input, output) {
  
  formulaText <- reactive({
    paste("Answers: ", input$variable)
  })
  
  output$caption <- renderText({
    formulaText()
  })
  
 output$MeTooPlot <- renderPlot({
  p <- ggplot(dane)
    
    p + geom_bar(aes(x=dane[,input$variable], fill=factor(dane[,input$var])),
                 color="black",
                position=input$dist)
    
    }) 
 
 output$MeTooPlot2 <- renderPlot({
   p <- ggplot(dane)
   
   p + geom_bar(aes(x=dane[,input$variable2], fill=factor(dane[,input$var2])),
                color="black",
                position=input$dist2)
 
 })
 
 output$MeTooPlot3 <- renderPlot({
   p <- ggplot(dane)
   
   p + geom_bar(aes(x=dane[,input$variable3], fill=factor(dane[,input$var3])),
                color="black",
                position=input$dist3)
 })
   
   
}


shinyApp(ui1, server1)


In which part do you read the csv file into r? Do you have a separate global.R file?
Also, what does your logs said?

maybe you should put print(p) or just p at the end of your renderPlot

p + geom_bar() has the same effect, I don't think that's the problem, besides, putting just p with that code would just do ggplot(dane)

1 Like

you are completely right sry!

At the beggining with this code

dane <- read.csv("dane_Stata1.csv", header=TRUE, sep=";")

I used the idea from this solution --> https://stackoverflow.com/questions/22927741/shinys-tabsetpanel-not-displaying-plots-in-multiple-tabs but it doesnt work. I have no error, just blank space, no plots as well.

If I want to show just one plot (and in UI and server I mention as well just one plot) it works properly. Problem starts once there are more plotOutputs in the code.

Why are you doing this dane[,input$variable] for defining your aesthetics instead of using tidy evaluation i. e. !!as.name(input$variable)?

I changed the thing you mentioned earlier, but it didnt work. So I deleted this part in the code in UI in the main panel of each tab

h3(textOutput("caption")

And yes! it works right now!! :blush:

thank you all for your help :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.