i need to give flexibility to app user so that they can edit/modify a table . I am using the below codes
UI code:
tabItem(tabName = "manual_override",
fluidRow(
editableDTUI("table1")
Server Codes:
callModule(editableDT,"table1",data=reactive(bigtable),inputwidth=reactive(100))
but the problem is that bigtable has more than 15 columns to display and the horizontal scroll is not appearing
I have tried the same with library(DT) with 20 col.
If that solves your problem.
ui.r
library(shiny)
library(DT)
shinyUI(
fluidPage(
navbarPage("Big file upload + Horizental Scrolling",
tabPanel("Data Import",
fluidRow(
fileInput("file","Upload Your CSV",multiple = FALSE),
column(6,
div(style = 'overflow-x: scroll', DT::dataTableOutput('csv_data')))
)
)
)
)
)
server.r
library(shiny)
shinyServer(function(input, output) {
csv_data_fun<-eventReactive(input$file,{
df<-read.csv(input$file$datapath,
header =TRUE)
return(df)
})
output$csv_data<-DT::renderDataTable({
DT::datatable(csv_data_fun(),rownames = FALSE)%>%formatStyle(columns=colnames(csv_data_fun()),background = 'white',color='black')
})
})
output Screen
Please check whether you want this
I have done with editDT, But this time with default mtcars dataset.
Added the code in UI part
div(style = 'overflow-x: scroll',editableDTUI("table1"))
New Code
library(shiny)
library(editData)
if (interactive()) {
ui <- fluidPage(
textInput("mydata","Enter data name",value="mtcars"),
column(6,
div(style = 'overflow-x: scroll',editableDTUI("table1")
)
)
)
server <- function(input, output) {
df=callModule(editableDT,"table1",dataname=reactive(input$mydata),inputwidth=reactive(170))
output$test=renderPrint({
str(df())
})
}
shinyApp(ui, server)
}
Please check this time if this solves your problem. You can tweak the things to change according to your requirements.
Please accept the answer if solves your issue.
Related
All of the buttons in a shiny app I am making use shinyWidgets. I also use a fileInput button and I would like the button of this to be in the same style as my shinyWidgets::actionBttn. Is there a way of doing this?
library(shiny)
library(shinyWidgets)
shinyUI(fluidPage(
# Application title
titlePanel("Uploac a file"),
fileInput("Myfile",label="",multiple = FALSE),br(),
actionBttn("textPrep",label = "Browse")
))
You can do something like this:
library(shiny)
library(shinyWidgets)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
# Application title
titlePanel("Upload a file"),
fileInput("Myfile", label="", multiple = FALSE),
br(),
actionBttn("textPrep", label = "Browse")
)
server <- function(input, output){
addCssClass(class = "bttn bttn-unite bttn-default bttn-no-outline",
selector = ".btn-file")
}
shinyApp(ui, server)
In my current application I am using a navlistPanel similar to the one below and I was wondering whether it would be possible to add a selectInput UI element to the navlist?
I have tried this in my ui.R but it doesn't work:
fluidPage(
titlePanel("Application Title"),
navlistPanel(
"Header",
tabPanel("First"),
tabPanel("Second"),
tabPanel("Third")
# selectInput(inputId, label, choices, selected = NULL) <- I've tried this but it doesn't work
)
)
Any solutions/workarounds are welcome.
I was wondering whether using sidebarLayout + sidebarPanel would work where the sidebarPanel imitates the behaviour of a navlistPanel but wasn't able to implement it.
A clean solution will be difficult, but how about something like this:
library(shiny)
shinyApp(
ui <- fluidPage(
titlePanel("Application Title"),
navlistPanel("Header", id = "navOut",
tabPanel("First", "First"),
tabPanel(selectInput("navSel", "Selection:", c("b", "c")), textOutput("txt"))
)
),
server <- shinyServer(function(input, output){
output$txt <- renderText(input$navSel)
})
)
If you are okay with using shinydashboard, it is fairly simple.
library(shiny)
library(shinydashboard)
rm(list=ls)
######/ UI Side/######
header <- dashboardHeader(title = "Test")
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("First Tab",tabName = "FTab", icon = icon("globe")),
menuItem("Second Tab",tabName = "STab", icon = icon("star"))
),
selectInput("navSel", "Selection:", c("b","c"))
)
body <- dashboardBody()
ui <- dashboardPage(header, sidebar, body)
######/ SERVER Side/######
server <- function(input, output, session) {
}
shinyApp(ui, server)
I have initial loading of data from the DB in the server.R which takes a few seconds. Until this is done, the page displayed is distorted (wrong data in selection box, and weird placing of the boxes, see below).
I want to display a different page (or at least different content in my first-displayed tab) until the data is completely loaded.
I thought about doing some kind of conditionalPanel using a condition based on a dedicated global variable (initial_loading_done), but wherever I tried placing the conditionalPanel it didn't work.
This is the structure of my UI.R:
shinyUI(
dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
sidebarMenu(
menuItem("Tab1", tabName = "Tab1",icon = icon("dashboard")),
menuItem("Tab2", tabName = "Tab2", icon = icon("bar-chart-o"))
)
),
dashboardBody(
includeCSS("custom_css.css"),
tabItems(
tabItem(tabName = "Tab1",
fluidRow(<content>),
mainPanel(
fluidRow(<content>)
)
),
tabItem(tabName = "Tab2",
fluidRow(<content>),
mainPanel(
dataTableOutput('my_data_table')
)
)
)
)
)
)
Here's a very simple example using shinyjs package
The idea is to create the loading "page" and the content "page" under different IDs, have the content page initially hidden, and use show() and hide() after the app is ready
library(shiny)
library(shinyjs)
load_data <- function() {
Sys.sleep(2)
hide("loading_page")
show("main_content")
}
ui <- fluidPage(
useShinyjs(),
div(
id = "loading_page",
h1("Loading...")
),
hidden(
div(
id = "main_content",
"Data loaded, content goes here"
)
)
)
server <- function(input, output, session) {
load_data()
}
shinyApp(ui = ui, server = server)
In server I like to use reactiveValues() to store a setupComplete condition. Then, when the data is loaded my setupComplete is set to TRUE.
In the ui we can then assess this setupComplete condition in a conditionalPanel, and only display the content (in my example the three box() widgets).
Here's a working example
## app.R ##
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
actionButton(inputId = "btn_data", label = "Download"),
conditionalPanel(condition = "output.setupComplete",
box( title = "box1" ),
box( title = "box2" ),
box( title = "boc3" )
),
conditionalPanel(condition = "!output.setupComplete",
box( title = "loading"))
)
)
server <- function(input, output) {
rv <- reactiveValues()
rv$setupComplete <- FALSE
## simulate data load
observe({
if(input$btn_data){
df <- data.frame(id = seq(1,200),
val = rnorm(200, 0, 1))
## Simulate the data load
Sys.sleep(5)
## set my condition to TRUE
rv$setupComplete <- TRUE
}
## the conditional panel reads this output
output$setupComplete <- reactive({
return(rv$setupComplete)
})
outputOptions(output, 'setupComplete', suspendWhenHidden=FALSE)
})
}
shinyApp(ui, server)
The code
hidden(
div(
id = "main_content",
"Data loaded, content goes here"
)
doesn't work with tabsetPanel. But if you move the id to the div level it works beautifully. Thanks to shinyjs author Dean Attali for this tip. https://stackoverflow.com/users/4432127/keshete
hidden(
div(id = "mainTabsetPanel",
tabsetPanel(
....
I have a shiny example using renderDataTable() to create an output.
I have removed all possible options (paging, filtering, searching, etc). However, there is now a blank row at the top and bottom of my table output, where the filtering and searching used to be.
How can I remove these two divs from inside the datatable wrapper, only when I have removed the filtering and searching options?
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("dataTable Example"),
sidebarPanel(
"This is a sidebar"
),
mainPanel(
p("Check out the gaps below."),
wellPanel(
dataTableOutput('example1')),
p("No gaps here because of searching and paging."),
wellPanel(
dataTableOutput('example2')
)
)
)
)
server.R:
library(shiny)
shinyServer(function(input, output) {
x<-c(1,2,3,4,5)
y<-c('a','b','c','d','e')
test<-data.frame(x,y)
output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
,bInfo=0,bSort=0))
output$example2<-renderDataTable({test})
})
You can use the sDom option see http://legacy.datatables.net/usage/options#sDom for more details:
library(shiny)
runApp(list( ui =pageWithSidebar(
headerPanel("dataTable Example"),
sidebarPanel(
"This is a sidebar"
),
mainPanel(
p("Check out the gaps below."),
wellPanel(
dataTableOutput('example1')),
p("No gaps here because of searching and paging."),
wellPanel(
dataTableOutput('example2')
)
)
)
, server = function(input, output) {
x<-c(1,2,3,4,5)
y<-c('a','b','c','d','e')
test<-data.frame(x,y)
output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
,bInfo=0,bSort=0
, "sDom" = "rt"
))
output$example2<-renderDataTable({test})
}
)
)
I have a shiny example using renderDataTable() to create an output.
I have removed all possible options (paging, filtering, searching, etc). However, there is now a blank row at the top and bottom of my table output, where the filtering and searching used to be.
How can I remove these two divs from inside the datatable wrapper, only when I have removed the filtering and searching options?
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("dataTable Example"),
sidebarPanel(
"This is a sidebar"
),
mainPanel(
p("Check out the gaps below."),
wellPanel(
dataTableOutput('example1')),
p("No gaps here because of searching and paging."),
wellPanel(
dataTableOutput('example2')
)
)
)
)
server.R:
library(shiny)
shinyServer(function(input, output) {
x<-c(1,2,3,4,5)
y<-c('a','b','c','d','e')
test<-data.frame(x,y)
output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
,bInfo=0,bSort=0))
output$example2<-renderDataTable({test})
})
You can use the sDom option see http://legacy.datatables.net/usage/options#sDom for more details:
library(shiny)
runApp(list( ui =pageWithSidebar(
headerPanel("dataTable Example"),
sidebarPanel(
"This is a sidebar"
),
mainPanel(
p("Check out the gaps below."),
wellPanel(
dataTableOutput('example1')),
p("No gaps here because of searching and paging."),
wellPanel(
dataTableOutput('example2')
)
)
)
, server = function(input, output) {
x<-c(1,2,3,4,5)
y<-c('a','b','c','d','e')
test<-data.frame(x,y)
output$example1<-renderDataTable({test},options = list(iDisplayLength = 5,bSearchable = FALSE
,bFilter=FALSE,bPaginate=FALSE,bAutoWidth=TRUE
,bInfo=0,bSort=0
, "sDom" = "rt"
))
output$example2<-renderDataTable({test})
}
)
)