I'm working on a shiny app and having an issue with my code. I've got a reactive text that changes based on a selectInput. For example if I choose "Character 1" in my selectInput I will have an output text: "Visualisation de Character 1". However, this works only when I select a specific tabPanel named "Métriques Wellness" and doesn't work with others.
Here's the code:
ui <- navbarPage(
title = "RCN Dashboard Visualisation",
theme = shinytheme("united"),
tags$head(
tags$style(HTML("
body {
background-color: darkgrey;
color: darkred;
font-size: 18px;
font-family: Impact;
}
.irs-bar {
background: darkgrey !important;
}
.irs-handle {
border: 2px solid darkgrey !important;
}
.irs-with-grid .irs span {
background: darkred !important;
}
.col-sm-3{
border: 3px solid darkred;
background-color: white ;
}
.col-sm-6+ .col-sm-6 , #cdduistsmi{
border: 3px solid darkred;
background-color: white;
}
.well{
border: 3px solid darkred;
}
.col-sm-8{
border: 3px solid darkred;
background-color: white;
}
.col-sm-8 , .col-sm-8 .col-sm-4{
border: 3px solid darkred;
background-color: white;
}
"))
),
tags$li(class = "dropdown",
tags$a(class = "logo-right",
tags$img(src = 'logo narbonne.png', height = '75px', align = 'right'))),
id = "mainNav", # ID pour les conditionalPanel
# Others tabPanel [...]
tabPanel(
"Métriques Charge d'entrainement",
sidebarLayout(
sidebar,
mainPanel(
"Visualisation des données",
h1(textOutput("selected_nom")),
plotlyOutput("graphique_17")
)
)
),
tabPanel(
"Métriques Wellness",
sidebarLayout(
sidebar,
mainPanel(
"Visualisation des données",
h1(textOutput("selected_nom")),
plotlyOutput("graphique_18"),
fluidRow(column(width = 8, plotlyOutput("graphique_19")),
column(width = 4, plotlyOutput("graphique_20")))
)
)
)
)
server <- function(input, output) {
output$selected_nom <- renderText({
paste("Visualisation de ", input$Nom)
}) # Création du titre selon l'athlète choisi dans le selectInput
I think the problem is more about syntax than anything.
the dput of my Athlete database, but I don't think that it will helps
filter(Nom == "Abadie")
> dput(test_8)
structure(list(Nom = c("Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie",
"Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie", "Abadie"
), Date = structure(c(19361, 19362, 19365, 19366, 19367, 19368,
19370, 19372, 19373, 19375, 19376, 19377, 19379, 19380, 19382,
19383, 19384, 19527, 19528, 19529, 19530, 19531, 19534, 19535,
19537, 19538, 19541, 19542, 19544, 19545, 19548, 19549, 19550,
19551, 19555, 19556, 19557, 19558, 19569, 19570, 19572, 19573,
19576, 19577, 19579, 19580, 19586, 19587, 19590, 19591, 19593,
19594, 19595, 19597, 19598, 19600, 19601, 19602, 19604, 19605,
19607, 19608, 19609, 19611, 19612, 19614, 19615, 19616, 19621,
19625, 19626, 19628, 19629, 19630, 19632, 19633, 19635, 19636,
19637, 19639, 19640, 19642, 19643, 19644, 19646, 19647, 19649,
19650, 19660, 19661, 19663, 19664, 19665, 19667, 19668, 19670,
19671, 19674, 19675, 19677, 19678, 19679, 19684, 19685, 19688,
19689, 19691, 19692, 19695, 19696, 19698, 19699, 19700, 19702,
19703, 19705, 19706, 19709, 19710, 19758, 19759, 19761, 19762,
19763, 19765, 19766, 19768, 19769, 19770, 19772, 19773, 19775,
19776, 19777, 19779, 19780, 19782, 19783, 19786, 19787, 19789,
19790, 19791, 19800, 19801, 19803, 19804, 19805, 19807, 19808,
19810, 19811, 19814, 19815, 19817, 19818, 19822, 19823, 19825,
19828, 19829, 19830, 19835, 19836, 19838), class = "Date"), CDE = c(540,
660, 375, 1328, 707, 659.2, 412.5, 548, 1308, 899, 147.6, 376,
375, 929, 824, 104, 280, 318, 731.5, 731.5, 900, 1068, 714.8,
1476, 700, 1018, 734.4, 1068, 1150, 1440, 1180, 1249.6, 729.1,
1848, 551, 2193, 960, 1228, 866, 1541.7, 958, 1041.4, 766, 1736,
784.3, 456, 780, 1145, 1020, 933.5, 609, 210, 440, 482.6, 972.5,
674, 247.5, 368, 455.8, 1256, 647.5, 560, 495, 576, 985, 976,
177, 240, 1051, 740.7, 1122, 934, 154.5, 240, 595, 1347, 823,
252, 512, 422, 1263, 756, 173.1, 240, 319, 1159, 690, 172, 975,
1174, 807, 172, 144, 210, 1123, 188, 384, 310.2, 425, 512, 120,
184, 600, 455, 794.5, 782, 162, 224, 424, 1171, 900, 294, 432,
216, 1051, 144, 408, 384, 408, 633, 1189, 956, 155, 272, 444,
1296, 902, 240, 408, 444, 1250, 676, 171, 432, 135, 447, 399,
627, 497, 1007, 872, 150, 320, 705, 1096, 904, 216, 224, 324,
845, 747, 600, 370, 886, 803, 705, 1239, 170, 480, 428, 708,
560, 592, 1243, 640), day = structure(c(4L, 5L, 1L, 2L, 3L, 4L,
6L, 1L, 2L, 4L, 5L, 6L, 1L, 2L, 4L, 5L, 6L, 2L, 3L, 4L, 5L, 6L,
2L, 3L, 5L, 6L, 2L, 3L, 5L, 6L, 2L, 3L, 4L, 5L, 2L, 3L, 4L, 5L,
2L, 3L, 5L, 6L, 2L, 3L, 5L, 6L, 5L, 6L, 2L, 3L, 5L, 6L, 7L, 2L,
3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 5L, 2L,
3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 2L, 3L,
5L, 6L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 2L, 3L, 5L, 6L, 7L,
5L, 6L, 2L, 3L, 5L, 6L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 2L,
3L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L,
2L, 3L, 5L, 6L, 2L, 3L, 5L, 6L, 7L, 2L, 3L, 5L, 6L, 7L, 2L, 3L,
5L, 6L, 2L, 3L, 5L, 6L, 3L, 4L, 6L, 2L, 3L, 4L, 2L, 3L, 5L), levels = c("Sun",
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), class = c("ordered",
"factor")), Moyenne_CDE = c(540, 660, 375, 1328, 707, 600, 412,
462, 1318, 699, 404, 394, 433, 1188, 731, 304, 356, 318, 732,
732, 900, 1068, 516, 1104, 800, 1043, 589, 1092, 917, 1175, 737,
1131, 730, 1150, 795, 1497, 845, 1232, 866, 1661, 1345, 1041,
728, 1824, 990, 749, 841, 881, 884, 1404, 783, 713, 440, 756,
1214, 712, 515, 404, 653, 1054, 678, 541, 434, 634, 1037, 727,
299, 386, 837, 591, 1121, 902, 297, 325, 637, 1151, 946, 194,
331, 586, 1244, 891, 193, 331, 519, 1223, 801, 188, 572, 1199,
751, 172, 192, 501, 1152, 562, 243, 498, 907, 502, 225, 164,
527, 283, 438, 777, 366, 296, 510, 793, 544, 273, 308, 478, 1001,
452, 345, 455, 853, 633, 1189, 956, 155, 272, 538, 1242, 929,
198, 340, 507, 1245, 845, 189, 371, 414, 1046, 733, 298, 380,
1000, 712, 297, 387, 446, 850, 725, 331, 272, 509, 983, 841,
322, 466, 942, 818, 507, 1016, 170, 500, 374, 920, 365, 463,
1019, 722), SD_CDE = c(NA, NA, NA, NA, NA, 84, NA, 122, 14, 183,
362, 26, 100, 225, 162, 309, 68, NA, NA, NA, NA, NA, 281, 526,
141, 35, 235, 373, 225, 231, 352, 314, 2, 501, 269, 493, 163,
472, 315, 483, 456, NA, 161, 334, 224, 414, 102, 372, 128, 419,
142, 452, NA, 269, 452, 85, 434, 51, 318, 176, 73, 432, 64, 263,
148, 168, 177, 110, 206, 143, 136, 177, 228, 147, 90, 183, 95,
51, 157, 160, 114, 129, 52, 157, 186, 102, 104, 44, 353, 56,
59, 1, 68, 414, 26, 329, 122, 416, 418, 310, 140, 28, 257, 162,
313, 349, 223, 152, 253, 373, 304, 141, 175, 293, 199, 366, 105,
244, 338, NA, NA, NA, NA, NA, 134, 76, 38, 60, 96, 109, 54, 149,
45, 86, 206, 401, 254, 222, 165, 390, 232, 223, 59, 288, 352,
283, 258, 68, 191, 127, 83, 243, 208, 135, 80, 257, 185, NA,
211, 52, 226, 276, 115, 266, 115), Z_Score_CDE = c(NA, NA, NA,
NA, NA, 0.71, NA, 0.71, -0.71, 1.09, -0.71, -0.71, -0.58, -1.15,
0.58, -0.65, -1.11, NA, NA, NA, NA, NA, 0.71, 0.71, -0.71, -0.71,
0.62, -0.06, 1.03, 1.15, 1.26, 0.38, -0.71, 1.39, -0.91, 1.41,
0.71, -0.01, 0, -0.25, -0.85, NA, 0.24, -0.26, -0.92, -0.71,
-0.6, 0.71, 1.06, -1.12, -1.22, -1.11, NA, -1.02, -0.53, -0.44,
-0.62, -0.71, -0.62, 1.15, -0.41, 0.04, 0.95, -0.22, -0.35, 1.48,
-0.69, -1.32, 1.04, 1.05, 0.01, 0.18, -0.63, -0.58, -0.47, 1.07,
-1.29, 1.13, 1.15, -1.03, 0.17, -1.04, -0.39, -0.58, -1.07, -0.62,
-1.06, -0.36, 1.14, -0.44, 0.95, -0.58, -0.71, -0.7, -1.11, -1.14,
1.15, -0.45, -1.15, 0.03, -0.75, 0.71, 0.28, 1.06, 1.14, 0.02,
-0.91, -0.47, -0.34, 1.01, 1.17, 0.15, 0.71, -0.89, 0.25, -0.84,
0.6, -0.29, -1.32, NA, NA, NA, NA, NA, -0.71, 0.71, -0.71, 0.71,
0.71, -0.58, 0.09, -1.14, -0.39, 0.71, -1.35, -1.49, -1.32, 1.48,
0.71, 0.02, 0.69, -0.66, -1.13, 0.9, 0.7, 0.63, -0.44, -0.71,
-0.97, -1.08, -1.13, 1.14, -0.46, -0.42, -0.19, 0.77, 1.21, NA,
-0.1, 1.04, -0.94, 0.71, 1.12, 0.84, -0.71)), row.names = c(NA,
-165L), class = c("tbl_df", "tbl", "data.frame"))
I got this:
But when I select another tabPanel, nothing:
Honestly, I didn't try anything since the code structure is similar. Do you have an idea to resolve that?
There is no need to create multiple textInput
's (referring to the comments below the question). You can simply copy the result of your renderText()
call to multiple outputs:
library(shiny)
ui <- fluidPage(
mainPanel(
textInput("Nom", "Nom", "Nom"),
tabsetPanel(
tabPanel("Tab1", textOutput("selected_nom1")),
tabPanel("Tab2", textOutput("selected_nom2")),
tabPanel("Tab3", textOutput("selected_nom3"))
)
)
)
server <- function(input, output, session) {
output$selected_nom1 <- output$selected_nom2 <- output$selected_nom3 <- renderText({
paste("Visualisation de ", input$Nom)
})
}
shinyApp(ui, server)
I've posted this approach here first.
However, looking into shiny's modules still is a proper advise.