How to display the column names of tables without dots replacing spaces and removing the table name in Shiny...
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
add a comment |
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
add a comment |
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
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
r function shiny
asked Nov 21 '18 at 18:25
CuisilopezCuisilopez
195
195
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
1
I agree, it works great now, the answer is super useful! Many thanks!
– Cuisilopez
Nov 22 '18 at 10:35
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
1
I agree, it works great now, the answer is super useful! Many thanks!
– Cuisilopez
Nov 22 '18 at 10:35
add a comment |
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
1
I agree, it works great now, the answer is super useful! Many thanks!
– Cuisilopez
Nov 22 '18 at 10:35
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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