SelectInput for multiple valueBoxes
up vote
1
down vote
favorite
I am looking for a way to have three separate valueBoxes respond to the same selectInput. My dataframe:
region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2
For selectInput I want Diarrhe, Fever and ARI as options, and I would like to see three Value boxes, one for Afghanistan, one for Boys and one for Girls with the value corresponding to input variable.
I cant seem to figure out how to this..
Thanks!
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_data",
label = "Indicator",
choices = overall[,c(2:4)]))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
valueBox(input$selected_data,subtitle = "Afghanistan")
})
}
shinyApp(ui = ui, server = server)
r shiny
add a comment |
up vote
1
down vote
favorite
I am looking for a way to have three separate valueBoxes respond to the same selectInput. My dataframe:
region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2
For selectInput I want Diarrhe, Fever and ARI as options, and I would like to see three Value boxes, one for Afghanistan, one for Boys and one for Girls with the value corresponding to input variable.
I cant seem to figure out how to this..
Thanks!
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_data",
label = "Indicator",
choices = overall[,c(2:4)]))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
valueBox(input$selected_data,subtitle = "Afghanistan")
})
}
shinyApp(ui = ui, server = server)
r shiny
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am looking for a way to have three separate valueBoxes respond to the same selectInput. My dataframe:
region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2
For selectInput I want Diarrhe, Fever and ARI as options, and I would like to see three Value boxes, one for Afghanistan, one for Boys and one for Girls with the value corresponding to input variable.
I cant seem to figure out how to this..
Thanks!
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_data",
label = "Indicator",
choices = overall[,c(2:4)]))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
valueBox(input$selected_data,subtitle = "Afghanistan")
})
}
shinyApp(ui = ui, server = server)
r shiny
I am looking for a way to have three separate valueBoxes respond to the same selectInput. My dataframe:
region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2
For selectInput I want Diarrhe, Fever and ARI as options, and I would like to see three Value boxes, one for Afghanistan, one for Boys and one for Girls with the value corresponding to input variable.
I cant seem to figure out how to this..
Thanks!
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_data",
label = "Indicator",
choices = overall[,c(2:4)]))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
valueBox(input$selected_data,subtitle = "Afghanistan")
})
}
shinyApp(ui = ui, server = server)
r shiny
r shiny
edited Dec 6 at 9:35
Cœur
17.3k9102142
17.3k9102142
asked Nov 22 at 13:39
Margo
83
83
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26
add a comment |
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You could make separate uiOutputs
, but a more concise approach would be to use lapply
inside the renderUI
to loop over your resulting dataframe
. Note that I renamed your input to selected_column
and I modified the options in the input.
A working example is given below, hope this helps!
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
box(width=12,
lapply(1:nrow(overall), function(i) {
valueBox(overall[i,input$selected_column],overall[i,'region'])})
)
})
}
shinyApp(ui = ui, server = server)
EDIT: As requested in your comment, this would be an example on how to make this work with separate UI elements:
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
box(width=12,
uiOutput("value_box1"),
uiOutput("value_box2")
)
)
)
server <- function(input, output) {
output$value_box1 <- renderUI({
valueBox(overall[1,input$selected_column],overall[1,'region'])
})
output$value_box2 <- renderUI({
valueBox(overall[2,input$selected_column],overall[2,'region'])
})
}
shinyApp(ui = ui, server = server)
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You could make separate uiOutputs
, but a more concise approach would be to use lapply
inside the renderUI
to loop over your resulting dataframe
. Note that I renamed your input to selected_column
and I modified the options in the input.
A working example is given below, hope this helps!
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
box(width=12,
lapply(1:nrow(overall), function(i) {
valueBox(overall[i,input$selected_column],overall[i,'region'])})
)
})
}
shinyApp(ui = ui, server = server)
EDIT: As requested in your comment, this would be an example on how to make this work with separate UI elements:
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
box(width=12,
uiOutput("value_box1"),
uiOutput("value_box2")
)
)
)
server <- function(input, output) {
output$value_box1 <- renderUI({
valueBox(overall[1,input$selected_column],overall[1,'region'])
})
output$value_box2 <- renderUI({
valueBox(overall[2,input$selected_column],overall[2,'region'])
})
}
shinyApp(ui = ui, server = server)
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
add a comment |
up vote
0
down vote
accepted
You could make separate uiOutputs
, but a more concise approach would be to use lapply
inside the renderUI
to loop over your resulting dataframe
. Note that I renamed your input to selected_column
and I modified the options in the input.
A working example is given below, hope this helps!
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
box(width=12,
lapply(1:nrow(overall), function(i) {
valueBox(overall[i,input$selected_column],overall[i,'region'])})
)
})
}
shinyApp(ui = ui, server = server)
EDIT: As requested in your comment, this would be an example on how to make this work with separate UI elements:
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
box(width=12,
uiOutput("value_box1"),
uiOutput("value_box2")
)
)
)
server <- function(input, output) {
output$value_box1 <- renderUI({
valueBox(overall[1,input$selected_column],overall[1,'region'])
})
output$value_box2 <- renderUI({
valueBox(overall[2,input$selected_column],overall[2,'region'])
})
}
shinyApp(ui = ui, server = server)
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You could make separate uiOutputs
, but a more concise approach would be to use lapply
inside the renderUI
to loop over your resulting dataframe
. Note that I renamed your input to selected_column
and I modified the options in the input.
A working example is given below, hope this helps!
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
box(width=12,
lapply(1:nrow(overall), function(i) {
valueBox(overall[i,input$selected_column],overall[i,'region'])})
)
})
}
shinyApp(ui = ui, server = server)
EDIT: As requested in your comment, this would be an example on how to make this work with separate UI elements:
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
box(width=12,
uiOutput("value_box1"),
uiOutput("value_box2")
)
)
)
server <- function(input, output) {
output$value_box1 <- renderUI({
valueBox(overall[1,input$selected_column],overall[1,'region'])
})
output$value_box2 <- renderUI({
valueBox(overall[2,input$selected_column],overall[2,'region'])
})
}
shinyApp(ui = ui, server = server)
You could make separate uiOutputs
, but a more concise approach would be to use lapply
inside the renderUI
to loop over your resulting dataframe
. Note that I renamed your input to selected_column
and I modified the options in the input.
A working example is given below, hope this helps!
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
uiOutput("value_box")
)
)
server <- function(input, output) {
output$value_box <- renderUI({
box(width=12,
lapply(1:nrow(overall), function(i) {
valueBox(overall[i,input$selected_column],overall[i,'region'])})
)
})
}
shinyApp(ui = ui, server = server)
EDIT: As requested in your comment, this would be an example on how to make this work with separate UI elements:
overall = read.table(text = 'region Diarrhea Fever ARI
Afghanistan 78.2 56.4 29.7
Boys 34.1 23.2 15.6
Girls 18.4 12.8 11.2', header=T)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, offset = 0, style = 'padding:1px;',
selectInput(inputId = "selected_column",
label = "Indicator",
choices = setdiff(colnames(overall),'region')))
)
)
),
box(width=12,
uiOutput("value_box1"),
uiOutput("value_box2")
)
)
)
server <- function(input, output) {
output$value_box1 <- renderUI({
valueBox(overall[1,input$selected_column],overall[1,'region'])
})
output$value_box2 <- renderUI({
valueBox(overall[2,input$selected_column],overall[2,'region'])
})
}
shinyApp(ui = ui, server = server)
edited Nov 27 at 6:57
answered Nov 22 at 16:16
Florian
16.8k31547
16.8k31547
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
add a comment |
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Hi Florian, thanks for the suggestions on improving my question, and of course for the solution to my problem! Works like a charm! Thanks!
– Margo
Nov 26 at 8:00
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Great, glad I could help :) Please consider accepting the answer to mark your question as resolved.
– Florian
Nov 26 at 8:14
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Certainly! If I am not asking too much of your time and wisdom - what would it look like if I were to use multiple uiOutputs responding to the same SelectInput, rather than looping through?
– Margo
Nov 26 at 11:11
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
Hi Margo, see the edit, I hope that is helpful.
– Florian
Nov 27 at 6:57
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
You're a hero! Thanks so much Florian
– Margo
Nov 27 at 11:28
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53432267%2fselectinput-for-multiple-valueboxes%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
Hi Margo, welcome to Stack Overflow! This is a very good first question on SO with a good small example to make it clear what you are looking for. There are some small improvements you could make to future questions to get your questions potentially answered even quicker, such as including the libraries and the data needed to reconstruct your problem, see here for some tips. Anyway, just small things :)
– Florian
Nov 22 at 16:26