How to extract cell content and column name when cell is clicked with DT package in Shiny?
Good morning and Happy Friday!
My issue are:
a) The example to extract cell content using mtcars is not working in my App, because when you click the cell, it gives you the value to the left.
b) I cannot get it to display the name of the column of the cell you clicked.
I am rendering these into a "summary box". Please click on the row 1 of column drat and then on row 1 of column wt. You will see what I am talking about.
Just one thing: My real app is like a school schedule, where the 1st column is Time. I don't need to extract the time as the people will see the time but not click on it. People will click on the "subjects" under colnames M-F. That's why I thought about adding 1 to the input$ing_table_cells_selected[2], since 2 is the column component and DT starts indexing at 0.
App is on "English" Tab.
Thank you very much! I appreciate any help you can give, as I have spent hours researching but it is not quite working.
## libraries
library(shinydashboard)
library(shiny)
library(data.table)
library(dplyr)
library(DT)
ui=dashboardPage(
dashboardHeader(title = "App"),
dashboardSidebar(
sidebarMenu(
menuItem("Español", tabName = "espanol", icon = icon("laptop")),
menuItem("English", tabName = "ingles", icon = icon("print"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "ingles",
h3("Data", style="color:DodgerBlue;text-align:center;font-family:Palatino Linotype;padding:0px;margin-top:0px;"),
fluidRow(
DT::dataTableOutput("ing_table"),
box(title = "Summary of Activities", status = "primary", solidHeader = TRUE,collapsible = TRUE,
DT::dataTableOutput("summary")
)
)))))
## SERVER SIDE ##########
server <- function(input, output) {
## using mtcars set as a example
output$ing_table= DT::renderDataTable(mtcars, options = list(searching = FALSE,bInfo=0,scrollX = TRUE, pageLength = 5), rownames=FALSE,selection = list(target = "cell"), server = FALSE)
# code to extract the cell value and make it reactive to feed output$summary
# I used "cell[2]" to access the column index and add 1, since in DT column index starts at 0 and I need the values starting col 1, not 0
reserved_act= reactive({
cell <- input$ing_table_cells_selected
data=data.frame(Values=mtcars[cell],Column_Names=colnames(mtcars[cell[2]+1]))
data
})
observeEvent(input$ing_table_cells_selected, {
output$summary = renderDataTable(reserved_act(), options = list(searching = FALSE,bInfo=0,scrollX = TRUE, paging=FALSE), rownames=FALSE)
})
}
shinyApp(ui, server)
shiny dt
add a comment |
Good morning and Happy Friday!
My issue are:
a) The example to extract cell content using mtcars is not working in my App, because when you click the cell, it gives you the value to the left.
b) I cannot get it to display the name of the column of the cell you clicked.
I am rendering these into a "summary box". Please click on the row 1 of column drat and then on row 1 of column wt. You will see what I am talking about.
Just one thing: My real app is like a school schedule, where the 1st column is Time. I don't need to extract the time as the people will see the time but not click on it. People will click on the "subjects" under colnames M-F. That's why I thought about adding 1 to the input$ing_table_cells_selected[2], since 2 is the column component and DT starts indexing at 0.
App is on "English" Tab.
Thank you very much! I appreciate any help you can give, as I have spent hours researching but it is not quite working.
## libraries
library(shinydashboard)
library(shiny)
library(data.table)
library(dplyr)
library(DT)
ui=dashboardPage(
dashboardHeader(title = "App"),
dashboardSidebar(
sidebarMenu(
menuItem("Español", tabName = "espanol", icon = icon("laptop")),
menuItem("English", tabName = "ingles", icon = icon("print"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "ingles",
h3("Data", style="color:DodgerBlue;text-align:center;font-family:Palatino Linotype;padding:0px;margin-top:0px;"),
fluidRow(
DT::dataTableOutput("ing_table"),
box(title = "Summary of Activities", status = "primary", solidHeader = TRUE,collapsible = TRUE,
DT::dataTableOutput("summary")
)
)))))
## SERVER SIDE ##########
server <- function(input, output) {
## using mtcars set as a example
output$ing_table= DT::renderDataTable(mtcars, options = list(searching = FALSE,bInfo=0,scrollX = TRUE, pageLength = 5), rownames=FALSE,selection = list(target = "cell"), server = FALSE)
# code to extract the cell value and make it reactive to feed output$summary
# I used "cell[2]" to access the column index and add 1, since in DT column index starts at 0 and I need the values starting col 1, not 0
reserved_act= reactive({
cell <- input$ing_table_cells_selected
data=data.frame(Values=mtcars[cell],Column_Names=colnames(mtcars[cell[2]+1]))
data
})
observeEvent(input$ing_table_cells_selected, {
output$summary = renderDataTable(reserved_act(), options = list(searching = FALSE,bInfo=0,scrollX = TRUE, paging=FALSE), rownames=FALSE)
})
}
shinyApp(ui, server)
shiny dt
add a comment |
Good morning and Happy Friday!
My issue are:
a) The example to extract cell content using mtcars is not working in my App, because when you click the cell, it gives you the value to the left.
b) I cannot get it to display the name of the column of the cell you clicked.
I am rendering these into a "summary box". Please click on the row 1 of column drat and then on row 1 of column wt. You will see what I am talking about.
Just one thing: My real app is like a school schedule, where the 1st column is Time. I don't need to extract the time as the people will see the time but not click on it. People will click on the "subjects" under colnames M-F. That's why I thought about adding 1 to the input$ing_table_cells_selected[2], since 2 is the column component and DT starts indexing at 0.
App is on "English" Tab.
Thank you very much! I appreciate any help you can give, as I have spent hours researching but it is not quite working.
## libraries
library(shinydashboard)
library(shiny)
library(data.table)
library(dplyr)
library(DT)
ui=dashboardPage(
dashboardHeader(title = "App"),
dashboardSidebar(
sidebarMenu(
menuItem("Español", tabName = "espanol", icon = icon("laptop")),
menuItem("English", tabName = "ingles", icon = icon("print"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "ingles",
h3("Data", style="color:DodgerBlue;text-align:center;font-family:Palatino Linotype;padding:0px;margin-top:0px;"),
fluidRow(
DT::dataTableOutput("ing_table"),
box(title = "Summary of Activities", status = "primary", solidHeader = TRUE,collapsible = TRUE,
DT::dataTableOutput("summary")
)
)))))
## SERVER SIDE ##########
server <- function(input, output) {
## using mtcars set as a example
output$ing_table= DT::renderDataTable(mtcars, options = list(searching = FALSE,bInfo=0,scrollX = TRUE, pageLength = 5), rownames=FALSE,selection = list(target = "cell"), server = FALSE)
# code to extract the cell value and make it reactive to feed output$summary
# I used "cell[2]" to access the column index and add 1, since in DT column index starts at 0 and I need the values starting col 1, not 0
reserved_act= reactive({
cell <- input$ing_table_cells_selected
data=data.frame(Values=mtcars[cell],Column_Names=colnames(mtcars[cell[2]+1]))
data
})
observeEvent(input$ing_table_cells_selected, {
output$summary = renderDataTable(reserved_act(), options = list(searching = FALSE,bInfo=0,scrollX = TRUE, paging=FALSE), rownames=FALSE)
})
}
shinyApp(ui, server)
shiny dt
Good morning and Happy Friday!
My issue are:
a) The example to extract cell content using mtcars is not working in my App, because when you click the cell, it gives you the value to the left.
b) I cannot get it to display the name of the column of the cell you clicked.
I am rendering these into a "summary box". Please click on the row 1 of column drat and then on row 1 of column wt. You will see what I am talking about.
Just one thing: My real app is like a school schedule, where the 1st column is Time. I don't need to extract the time as the people will see the time but not click on it. People will click on the "subjects" under colnames M-F. That's why I thought about adding 1 to the input$ing_table_cells_selected[2], since 2 is the column component and DT starts indexing at 0.
App is on "English" Tab.
Thank you very much! I appreciate any help you can give, as I have spent hours researching but it is not quite working.
## libraries
library(shinydashboard)
library(shiny)
library(data.table)
library(dplyr)
library(DT)
ui=dashboardPage(
dashboardHeader(title = "App"),
dashboardSidebar(
sidebarMenu(
menuItem("Español", tabName = "espanol", icon = icon("laptop")),
menuItem("English", tabName = "ingles", icon = icon("print"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "ingles",
h3("Data", style="color:DodgerBlue;text-align:center;font-family:Palatino Linotype;padding:0px;margin-top:0px;"),
fluidRow(
DT::dataTableOutput("ing_table"),
box(title = "Summary of Activities", status = "primary", solidHeader = TRUE,collapsible = TRUE,
DT::dataTableOutput("summary")
)
)))))
## SERVER SIDE ##########
server <- function(input, output) {
## using mtcars set as a example
output$ing_table= DT::renderDataTable(mtcars, options = list(searching = FALSE,bInfo=0,scrollX = TRUE, pageLength = 5), rownames=FALSE,selection = list(target = "cell"), server = FALSE)
# code to extract the cell value and make it reactive to feed output$summary
# I used "cell[2]" to access the column index and add 1, since in DT column index starts at 0 and I need the values starting col 1, not 0
reserved_act= reactive({
cell <- input$ing_table_cells_selected
data=data.frame(Values=mtcars[cell],Column_Names=colnames(mtcars[cell[2]+1]))
data
})
observeEvent(input$ing_table_cells_selected, {
output$summary = renderDataTable(reserved_act(), options = list(searching = FALSE,bInfo=0,scrollX = TRUE, paging=FALSE), rownames=FALSE)
})
}
shinyApp(ui, server)
shiny dt
shiny dt
asked Nov 23 '18 at 14:18
Will Will
163
163
add a comment |
add a comment |
0
active
oldest
votes
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%2f53448357%2fhow-to-extract-cell-content-and-column-name-when-cell-is-clicked-with-dt-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53448357%2fhow-to-extract-cell-content-and-column-name-when-cell-is-clicked-with-dt-package%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