I am building a fairly simple Shiny app that has a table on the first tab with an editable column using the rhandsontable
library. I want to have a new table created in the 2nd tab that contains any row in which the editable column is not blank.
Here is my code so far:
#----- Load libraries -----#
library(shiny)
library(shinydashboard)
library(DT)
library(shinyWidgets)
library(dplyr)
library(rhandsontable)
#----- Read in dataset -----#
df = mtcars
df$insert_info=NA
#----- Create lists -----#
binary_list = c('Yes','No')
# Define UI for application
ui <- fluidPage(
dashboardPage(
dashboardHeader(title="Draft"),
dashboardSidebar(
sidebarMenu(
menuItem("All Data",
tabName = "all_data",
icon=icon("table")
),
menuItem("Filtered Data",
tabName = "filtered_data",
icon = icon("table")
)
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "all_data",
rHandsontableOutput("all_table")
),
tabItem(
tabName = 'filtered_data',
rHandsontableOutput("filtered_table")
)
))))
# Define server logic
server <- function(input, output) {
#----------All Data Table----------#
output$all_table=renderRHandsontable({
my_table = rhandsontable(df) %>%
hot_col(c(1:11), readOnly = TRUE) %>%
hot_col(12,type='dropdown',source=binary_list) %>%
hot_context_menu(allowRowEdit = FALSE, allowColEdit = FALSE) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE)
return(my_table)
})
#----------Filtered Data Table----------#
output$filtered_table=renderRHandsontable({
#return all_table[,c(1,2,3,12)]
})
}
# Run the application
shinyApp(ui = ui, server = server)
If I were to select values from the dropdown menus of the last column for the first three rows, then I would want the new table on the 2nd tab to populate with those first three rows.
How should I go about creating this logic? Any help would be appreciated. Thank you!
...