I have a data frame with a lot of rows and columns, so I added a horizontal scroll bar so the columns wouldn't be squished. However In order to access the scroll bar I need to scroll all the way to the bottom of the datatable.
Is there an option to lock the horizontal scroll bar to the bottom of your screen and not the bottom of the datatable in the base DT package or do I need a DT extension?
output$sheet <- renderDT({
datatable(
display_table(),
options = list(
scrollX = TRUE,
autoWidth = TRUE,
pageLength = nrow(display_table()),
columnDefs = list(
list(width = "65px", targets = c(1,11)),
list(className = 'dt-center', targets = "_all")
)
)
)
})
Related
I am new to the world of RShiny and i think reactivity is bit complex to understand. I am trying to make a datatable output based on row and column condition given as per user selectinput dropdown buttons. My DataTable is editable and i want to store the updated table after user edited the cells of the datatable in a new variable but i am stuck.
I tried couple of chunks suggested on stackoverflow but none of them worked for me mostly using proxytable or reactivity. I want to store the datatable after i hit proceed button. Any help would be much appreciated.
Here is my code:
library(shiny)
library(shinyWidgets)
library(shinythemes)
library(DT)
library(data.table)
#ui
shinyApp(
ui = fluidPage(
theme = shinythemes::shinytheme("flatly"),
titlePanel("Trial"),
sidebarLayout(
shiny::sidebarPanel(
#to take multiple user input
shiny::textAreaInput(
"text_input",
label = "Write input"
),
#to slect the columns to be added
shinyWidgets::pickerInput(
inputId = "somevalue",
label = "Columns to add",
choices = colnames(df),
options = list(`actions-box` = TRUE),
multiple = TRUE
),
#action button tot show the table
shinyWidgets::actionBttn(
"show_table",
label = "Show",
size = "sm",
color = "default",
block = TRUE
), width = 2
),
mainPanel(
shiny::tabsetPanel(type = "tabs",
shiny::tabPanel("Table", DT::dataTableOutput("table")),
actionBttn("proceed","proceed")
),width = 10
)
)
),
server = function(input, output,session) {
#to add reactivity to the show button
df_filter <- reactive({
text_input <- trimws(strsplit(input$text_input, ",")[[1]])
df_filter <- df[df$make %chin% text_input, input$somevalue]
})%>% shiny::bindEvent(input$show_table)
#to output hte dt table with the filters
output$table <- DT::renderDT({
DT::datatable(df_filter(),
editable = 'cell',
options = list(scrollX = TRUE , lengthChange = FALSE, autoWidth = TRUE)
# editable = list(target = "row", disable = list(columns = c(2, 4, 5))))
)
})%>% shiny::bindEvent(df_filter())
}
)
I understand scrollY should constrain the height of the data table. I have a data table configured as below, but when I choose a page size of 100, the table just expands. I want the table to remain visible on the page, with the page navigation at the bottom always visible, and the user to have to scroll through the content.
output$search_results <- DT::renderDataTable(filtered_df(),
server=TRUE,
extensions = c('Buttons', 'ColReorder', 'FixedColumns','FixedHeader', 'KeyTable'),
options = list(
#dom = 'Blfrtip',
dom = 'Blptilp',
colReorder = TRUE,
buttons = c('copy', 'csv', 'excel'),
autoWidth = TRUE,
scrollX = TRUE,
scrollY = "500px",
fixedColumns = list(leftColumns = 2),
fixedHeader = TRUE,
keys=TRUE,
lengthMenu = c(5,10,20,50,100),
columnDefs = list(list(width = '500px', targets = c(0,1)))
)
)
I'm trying to eliminate the space between this table and the left side of browser window, but when I do, it messes up the spacing of the nav bar links and title.
How can I remove padding/margin on the excelR table, without altering the padding/margin of the navbar/ui/li elements?
library(shiny)
library(excelR)
shinyApp(
ui = navbarPage("title", selected = "main",
position = "fixed-top",
tags$style(type="text/css", "body {padding-top: 70px;}"),
tags$head(
tags$style(
"body {overflow-y: hidden;}"
)
),
tags$head(
tags$style(type = "text/css", ".container-fluid {padding-left:0px;
padding-right:0px; margin-right:0px; margin-left:0px;}")
),
tabPanel("main", id = "main",
fluidPage(
excelOutput("table", width = "100%", height = "1000px")
#htmlOutput("table", width = "100%", height = "500px")
)
)
),
server = function(input, output, session) {
output$table <-renderExcel(
excelTable(
data = iris,
autoColTypes = FALSE,
autoFill = TRUE,
fullscreen = FALSE,
lazyLoading = TRUE,
search = TRUE,
tableHeight = "800px",
pagination <- NULL
)
)
}
)
You can simply add this additional css to your code:
tags$style(type = "text/css", ".navbar{padding-left:15px;
padding-right:15px ; margin-right:auto; margin-left:auto;}")
),
Hope this helps!
Is there an easy way to create something like this in shiny?
RStudio is currently working on the sortable package: RStudio/sortable
Beware that it's currently in development (tagged as experimental), so major changes are possible and it's only accessble through GitHub
# install.packages("remotes")
# remotes::install_github("rstudio/sortable")
library(shiny)
library(sortable)
ui <- fluidPage(
fluidRow(
column(
width = 12,
bucket_list(
header = "Drag the items in any desired bucket",
group_name = "bucket_list_group",
add_rank_list(
text = "Drag from here",
labels = c("Ant", "Cat", "Eagle", "Giraffe", "Bear", "Frog","Dog"),
input_id = "rank_list_1"
),
add_rank_list(
text = "to here",
labels = NULL,
input_id = "rank_list_2"
)
)
)
)
)
shinyApp(ui, function(input,output) {})
This results in:
The following code works to an extent - it plots a graph, but it is very clearly not subsetting the original data frame, but plotting based on all the indicators, years etc. Any thoughts on why? I have tried wrapping in reactive, using select(filter from dplyr, using "" around the input$indicator etc. I have spent about 4 hours looking through various suggestions on here, Plotly and Shiny sites, without a solution. Starting to doubt I'll ever get the hang of this.
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
library(dplyr)
library(shiny)
library(fingertipsR)
library(viridis)
library(plotly)
#Import QOF indicators
setwd("/Users/ianbowns/Documents/R/ShinyFT")
dat <- readRDS("data")
my.df <- as.data.frame(dat)
# Define UI for application that draws boxplot
ui <- fluidPage(
# Application title
titlePanel("FingerTips QOF Prevalences"),
# Input for year, area and indicator
sidebarLayout(
sidebarPanel(
selectInput(inputId = "indicator",
label = "Choose indicator:",
choices = levels(my.df$IndicatorName),
selected = "Hypertension: QOF prevalence (all ages)"),
selectInput(inputId = "areatype",
label = "Type of area:",
choices = levels(my.df$AreaType),
selected = "County & UA"),
selectInput(inputId = "year",
label = "Choose a year:",
choices = levels(my.df$Timeperiod),
selected = "2015/16")),
# Show a plot of the generated distribution
mainPanel(
plotlyOutput("bPlot", height = 500, width = 1000)
)
))
# Define server logic required to draw a histogram
server <- function(input, output) {
# draw the boxplot
output$bPlot <- renderPlotly({
plot_ly(data = subset(my.df, my.df$IndicatorName ==
input$indicator & my.df$AreaType == input$areatype &
my.df$Timeperiod == input$year), y = my.df$Value, color
= my.df$ParentName, type = "box",
colors = viridis_pal(alpha = 1, begin = 0, end = 1,
direction = -1, option = "D")(3)) %>%
layout(title = input$indicator, titlefont = list(family
= "Helvetica", size = 16),
xaxis = list(type = "category", tickfont = list(family =
"Helvetica", size = 8)),
yaxis = list(title = "Prevalence (%)", titlefont =
list(family = "Helvetica", size = 12)))})
}
# Run the application
shinyApp(ui = ui, server = server)