How to display the column names of tables without dots replacing spaces and removing the table name in Shiny...












1















I am building a complex Shiny App with many tables that are produced as the output of a function that I call here test for simplicity.



I then want to display theses tables with the right column names that i have assigned through the function, however they show with dots instead of spaces or parenthesis. On top of that, the name of the table is also displayed (which I don't want)



Any idea on how to display the correct column names: var test 1 and var test (2)?



Below, my code:



library(shiny)
library(ggplot)


ui <- fluidPage(


sidebarLayout(
sidebarPanel(
selectInput("A","Test",choices=c(1,2,3)),
actionButton("go","GO")
),


mainPanel(
plotOutput("graph1"),
tableOutput("table1")
)

))

server <- function(input, output) {

test<-function(A){
C<-(1:3)
A<-as.numeric(A)
dfA<-data.frame(A,C)
colnames(dfA)<-c("var test 1","var test (2)")
g1<-dfA


g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
geom_point(shape=1)


outputs<-list("output1"=g1,
"output2"=g2)
}


model_output<-eventReactive(input$go,{
test(input$A)
})

output$graph1<-renderPlot({
model_output()[2]

})
output$table1<-renderTable({
model_output()[1]

})



}

shinyApp(ui = ui, server = server)









share|improve this question



























    1















    I am building a complex Shiny App with many tables that are produced as the output of a function that I call here test for simplicity.



    I then want to display theses tables with the right column names that i have assigned through the function, however they show with dots instead of spaces or parenthesis. On top of that, the name of the table is also displayed (which I don't want)



    Any idea on how to display the correct column names: var test 1 and var test (2)?



    Below, my code:



    library(shiny)
    library(ggplot)


    ui <- fluidPage(


    sidebarLayout(
    sidebarPanel(
    selectInput("A","Test",choices=c(1,2,3)),
    actionButton("go","GO")
    ),


    mainPanel(
    plotOutput("graph1"),
    tableOutput("table1")
    )

    ))

    server <- function(input, output) {

    test<-function(A){
    C<-(1:3)
    A<-as.numeric(A)
    dfA<-data.frame(A,C)
    colnames(dfA)<-c("var test 1","var test (2)")
    g1<-dfA


    g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
    geom_point(shape=1)


    outputs<-list("output1"=g1,
    "output2"=g2)
    }


    model_output<-eventReactive(input$go,{
    test(input$A)
    })

    output$graph1<-renderPlot({
    model_output()[2]

    })
    output$table1<-renderTable({
    model_output()[1]

    })



    }

    shinyApp(ui = ui, server = server)









    share|improve this question

























      1












      1








      1








      I am building a complex Shiny App with many tables that are produced as the output of a function that I call here test for simplicity.



      I then want to display theses tables with the right column names that i have assigned through the function, however they show with dots instead of spaces or parenthesis. On top of that, the name of the table is also displayed (which I don't want)



      Any idea on how to display the correct column names: var test 1 and var test (2)?



      Below, my code:



      library(shiny)
      library(ggplot)


      ui <- fluidPage(


      sidebarLayout(
      sidebarPanel(
      selectInput("A","Test",choices=c(1,2,3)),
      actionButton("go","GO")
      ),


      mainPanel(
      plotOutput("graph1"),
      tableOutput("table1")
      )

      ))

      server <- function(input, output) {

      test<-function(A){
      C<-(1:3)
      A<-as.numeric(A)
      dfA<-data.frame(A,C)
      colnames(dfA)<-c("var test 1","var test (2)")
      g1<-dfA


      g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
      geom_point(shape=1)


      outputs<-list("output1"=g1,
      "output2"=g2)
      }


      model_output<-eventReactive(input$go,{
      test(input$A)
      })

      output$graph1<-renderPlot({
      model_output()[2]

      })
      output$table1<-renderTable({
      model_output()[1]

      })



      }

      shinyApp(ui = ui, server = server)









      share|improve this question














      I am building a complex Shiny App with many tables that are produced as the output of a function that I call here test for simplicity.



      I then want to display theses tables with the right column names that i have assigned through the function, however they show with dots instead of spaces or parenthesis. On top of that, the name of the table is also displayed (which I don't want)



      Any idea on how to display the correct column names: var test 1 and var test (2)?



      Below, my code:



      library(shiny)
      library(ggplot)


      ui <- fluidPage(


      sidebarLayout(
      sidebarPanel(
      selectInput("A","Test",choices=c(1,2,3)),
      actionButton("go","GO")
      ),


      mainPanel(
      plotOutput("graph1"),
      tableOutput("table1")
      )

      ))

      server <- function(input, output) {

      test<-function(A){
      C<-(1:3)
      A<-as.numeric(A)
      dfA<-data.frame(A,C)
      colnames(dfA)<-c("var test 1","var test (2)")
      g1<-dfA


      g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
      geom_point(shape=1)


      outputs<-list("output1"=g1,
      "output2"=g2)
      }


      model_output<-eventReactive(input$go,{
      test(input$A)
      })

      output$graph1<-renderPlot({
      model_output()[2]

      })
      output$table1<-renderTable({
      model_output()[1]

      })



      }

      shinyApp(ui = ui, server = server)






      r function shiny






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 18:25









      CuisilopezCuisilopez

      195




      195
























          1 Answer
          1






          active

          oldest

          votes


















          -1














          The issue is in the extraction of list elements. It should be [[ instead of [ because when we do [, it is still a list with one element



          model_output()[[1]]


          and



          model_output()[[2]]


          If we try to reproduce the issue



          o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
          o1[1]
          $g1 # note it is still a `list`
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3

          str(o1[1])
          List of 1
          # $ g1:'data.frame': 3 obs. of 2 variables:
          # ..$ var test 1 : num [1:3] 1 1 1
          # ..$ var test (2): int [1:3] 1 2 3

          o1[[1]]
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3


          -full code



          library(shiny)
          library(ggplot2)


          ui <- fluidPage(


          sidebarLayout(
          sidebarPanel(
          selectInput("A","Test",choices=c(1,2,3)),
          actionButton("go","GO")
          ),


          mainPanel(
          plotOutput("graph1"),
          tableOutput("table1")
          )

          ))

          server <- function(input, output) {

          test<-function(A){
          C<-(1:3)
          A<-as.numeric(A)
          dfA<-data.frame(A,C)
          colnames(dfA)<-c("var test 1","var test (2)")
          g1<-dfA


          g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
          geom_point(shape=1)


          outputs<-list("output1"=g1,
          "output2"=g2)
          }


          model_output<-eventReactive(input$go,{
          test(input$A)
          })

          output$graph1<-renderPlot({
          model_output()[[2]]

          })
          output$table1<-renderTable({
          model_output()[[1]]

          })



          }

          shinyApp(ui = ui, server = server)


          -output



          enter image description here






          share|improve this answer





















          • 1





            I agree, it works great now, the answer is super useful! Many thanks!

            – Cuisilopez
            Nov 22 '18 at 10:35











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418384%2fhow-to-display-the-column-names-of-tables-without-dots-replacing-spaces-and-remo%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          -1














          The issue is in the extraction of list elements. It should be [[ instead of [ because when we do [, it is still a list with one element



          model_output()[[1]]


          and



          model_output()[[2]]


          If we try to reproduce the issue



          o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
          o1[1]
          $g1 # note it is still a `list`
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3

          str(o1[1])
          List of 1
          # $ g1:'data.frame': 3 obs. of 2 variables:
          # ..$ var test 1 : num [1:3] 1 1 1
          # ..$ var test (2): int [1:3] 1 2 3

          o1[[1]]
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3


          -full code



          library(shiny)
          library(ggplot2)


          ui <- fluidPage(


          sidebarLayout(
          sidebarPanel(
          selectInput("A","Test",choices=c(1,2,3)),
          actionButton("go","GO")
          ),


          mainPanel(
          plotOutput("graph1"),
          tableOutput("table1")
          )

          ))

          server <- function(input, output) {

          test<-function(A){
          C<-(1:3)
          A<-as.numeric(A)
          dfA<-data.frame(A,C)
          colnames(dfA)<-c("var test 1","var test (2)")
          g1<-dfA


          g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
          geom_point(shape=1)


          outputs<-list("output1"=g1,
          "output2"=g2)
          }


          model_output<-eventReactive(input$go,{
          test(input$A)
          })

          output$graph1<-renderPlot({
          model_output()[[2]]

          })
          output$table1<-renderTable({
          model_output()[[1]]

          })



          }

          shinyApp(ui = ui, server = server)


          -output



          enter image description here






          share|improve this answer





















          • 1





            I agree, it works great now, the answer is super useful! Many thanks!

            – Cuisilopez
            Nov 22 '18 at 10:35
















          -1














          The issue is in the extraction of list elements. It should be [[ instead of [ because when we do [, it is still a list with one element



          model_output()[[1]]


          and



          model_output()[[2]]


          If we try to reproduce the issue



          o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
          o1[1]
          $g1 # note it is still a `list`
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3

          str(o1[1])
          List of 1
          # $ g1:'data.frame': 3 obs. of 2 variables:
          # ..$ var test 1 : num [1:3] 1 1 1
          # ..$ var test (2): int [1:3] 1 2 3

          o1[[1]]
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3


          -full code



          library(shiny)
          library(ggplot2)


          ui <- fluidPage(


          sidebarLayout(
          sidebarPanel(
          selectInput("A","Test",choices=c(1,2,3)),
          actionButton("go","GO")
          ),


          mainPanel(
          plotOutput("graph1"),
          tableOutput("table1")
          )

          ))

          server <- function(input, output) {

          test<-function(A){
          C<-(1:3)
          A<-as.numeric(A)
          dfA<-data.frame(A,C)
          colnames(dfA)<-c("var test 1","var test (2)")
          g1<-dfA


          g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
          geom_point(shape=1)


          outputs<-list("output1"=g1,
          "output2"=g2)
          }


          model_output<-eventReactive(input$go,{
          test(input$A)
          })

          output$graph1<-renderPlot({
          model_output()[[2]]

          })
          output$table1<-renderTable({
          model_output()[[1]]

          })



          }

          shinyApp(ui = ui, server = server)


          -output



          enter image description here






          share|improve this answer





















          • 1





            I agree, it works great now, the answer is super useful! Many thanks!

            – Cuisilopez
            Nov 22 '18 at 10:35














          -1












          -1








          -1







          The issue is in the extraction of list elements. It should be [[ instead of [ because when we do [, it is still a list with one element



          model_output()[[1]]


          and



          model_output()[[2]]


          If we try to reproduce the issue



          o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
          o1[1]
          $g1 # note it is still a `list`
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3

          str(o1[1])
          List of 1
          # $ g1:'data.frame': 3 obs. of 2 variables:
          # ..$ var test 1 : num [1:3] 1 1 1
          # ..$ var test (2): int [1:3] 1 2 3

          o1[[1]]
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3


          -full code



          library(shiny)
          library(ggplot2)


          ui <- fluidPage(


          sidebarLayout(
          sidebarPanel(
          selectInput("A","Test",choices=c(1,2,3)),
          actionButton("go","GO")
          ),


          mainPanel(
          plotOutput("graph1"),
          tableOutput("table1")
          )

          ))

          server <- function(input, output) {

          test<-function(A){
          C<-(1:3)
          A<-as.numeric(A)
          dfA<-data.frame(A,C)
          colnames(dfA)<-c("var test 1","var test (2)")
          g1<-dfA


          g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
          geom_point(shape=1)


          outputs<-list("output1"=g1,
          "output2"=g2)
          }


          model_output<-eventReactive(input$go,{
          test(input$A)
          })

          output$graph1<-renderPlot({
          model_output()[[2]]

          })
          output$table1<-renderTable({
          model_output()[[1]]

          })



          }

          shinyApp(ui = ui, server = server)


          -output



          enter image description here






          share|improve this answer















          The issue is in the extraction of list elements. It should be [[ instead of [ because when we do [, it is still a list with one element



          model_output()[[1]]


          and



          model_output()[[2]]


          If we try to reproduce the issue



          o1 <- list(g1 = data.frame(`var test 1` = 1, `var test (2)` = 1:3, check.names = FALSE))
          o1[1]
          $g1 # note it is still a `list`
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3

          str(o1[1])
          List of 1
          # $ g1:'data.frame': 3 obs. of 2 variables:
          # ..$ var test 1 : num [1:3] 1 1 1
          # ..$ var test (2): int [1:3] 1 2 3

          o1[[1]]
          # var test 1 var test (2)
          #1 1 1
          #2 1 2
          #3 1 3


          -full code



          library(shiny)
          library(ggplot2)


          ui <- fluidPage(


          sidebarLayout(
          sidebarPanel(
          selectInput("A","Test",choices=c(1,2,3)),
          actionButton("go","GO")
          ),


          mainPanel(
          plotOutput("graph1"),
          tableOutput("table1")
          )

          ))

          server <- function(input, output) {

          test<-function(A){
          C<-(1:3)
          A<-as.numeric(A)
          dfA<-data.frame(A,C)
          colnames(dfA)<-c("var test 1","var test (2)")
          g1<-dfA


          g2<-ggplot(data = dfA, aes(x=`var test 1`, y=`var test (2)`))+
          geom_point(shape=1)


          outputs<-list("output1"=g1,
          "output2"=g2)
          }


          model_output<-eventReactive(input$go,{
          test(input$A)
          })

          output$graph1<-renderPlot({
          model_output()[[2]]

          })
          output$table1<-renderTable({
          model_output()[[1]]

          })



          }

          shinyApp(ui = ui, server = server)


          -output



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 18:54

























          answered Nov 21 '18 at 18:37









          akrunakrun

          416k13205278




          416k13205278








          • 1





            I agree, it works great now, the answer is super useful! Many thanks!

            – Cuisilopez
            Nov 22 '18 at 10:35














          • 1





            I agree, it works great now, the answer is super useful! Many thanks!

            – Cuisilopez
            Nov 22 '18 at 10:35








          1




          1





          I agree, it works great now, the answer is super useful! Many thanks!

          – Cuisilopez
          Nov 22 '18 at 10:35





          I agree, it works great now, the answer is super useful! Many thanks!

          – Cuisilopez
          Nov 22 '18 at 10:35




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418384%2fhow-to-display-the-column-names-of-tables-without-dots-replacing-spaces-and-remo%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?