I have a shiny dashboard where I'm trying to use action buttons to select through what to show instead of the menu tabs. I have it built so that when you click the action button assigned to one specific fluid row it will hide the other tabs, but I can't seem to get it to bring the fluid row back. I'm using shinyjs show and hide functions.
this is the code I have in my ui
dashboardBody(
tags$head(
tags$link(
rel = "stylesheet",
type = "text/css",
href = "datainstate_style.css")
),
useShinyjs(),
introjsUI(),
# MAIN BODY ----------------------------------------------------------------
fluidRow(
column(
width = 12,
bsButton("VsOpponent",
label = "Vs Opponent",
icon = icon("users"),
style = "success"),
bsButton("trendsinperformance",
label = "Trends",
icon = icon("digital-tachograph"),
style = "success"),
bsButton("lineupsandchampions",
label = "Lineups and Champions",
icon = icon("child"),
style = "success")
)
),
fluidRow(
div( id = "VsOpponent_panel",
column(
width = 12,
gt_output("opponents_table")
),
column(
width = 12,
plotOutput("radar_plot")
),
column(
width = 12,
plotOutput("gold_plot")
)
)
),
fluidRow(
div( id = "trendsinperformance_panel",
column(
width = 12,
plotOutput("gold")
)
)
),
fluidRow(
div( id = "lineupsandchampions_panel",
column(
width = 12,
textOutput("test")
)
)
)
)
And then the code in my server that corresponds to this is below
## Determine which panel to show
observeEvent("", {
show("VsOpponent_panel")
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
}, once = TRUE)
observeEvent(input$VsOpponent, {
show("VsOpponent_panel")
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
})
observeEvent(input$trendsinperformance, {
show("trendsinperformance_panel")
hide("lineupsandchampions_panel")
hide("VsOpponent_panel")
})
observeEvent(input$lineupsandchampions, {
show("lineupsandchampions_panel")
hide("trendsinperformance_panel")
hide("VsOpponent_panel")
})
Thanks for your help!
Hmm, the buttons seem to work for me as expected, try to hide the divs first then show the other ones
library(shiny)
library(shinyjs)
library(shinyBS)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
width = 4,
bsButton("VsOpponent",
label = "Vs Opponent",
icon = icon("users"),
style = "success"),
bsButton("trendsinperformance",
label = "Trends",
icon = icon("digital-tachograph"),
style = "success"),
bsButton("lineupsandchampions",
label = "Lineups and Champions",
icon = icon("child"),
style = "success")
)
),
fluidRow(
div(id = "VsOpponent_panel",
column(
width = 4,
plotOutput("p1")
),
column(
width = 4,
plotOutput("p2")
),
column(
width = 4,
plotOutput("p3")
)
)
),
fluidRow(
div( id = "trendsinperformance_panel",
column(
width = 4,
plotOutput("p4")
)
)
),
fluidRow(
div( id = "lineupsandchampions_panel",
column(
width = 4,
plotOutput("p5")
)
)
)
)
server <- function(input, output, session) {
output$p1 <- renderPlot({plot(runif(10),main = "Plot1")})
output$p2 <- renderPlot({plot(runif(10),main = "Plot2")})
output$p3 <- renderPlot({plot(runif(10),main = "Plot3")})
output$p4 <- renderPlot({plot(runif(10),main = "Plot4")})
output$p5 <- renderPlot({plot(runif(10),main = "Plot5")})
## Determine which panel to show
observeEvent("", {
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
show("VsOpponent_panel")
}, once = TRUE)
observeEvent(input$VsOpponent, {
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
show("VsOpponent_panel")
})
observeEvent(input$trendsinperformance, {
hide("lineupsandchampions_panel")
hide("VsOpponent_panel")
show("trendsinperformance_panel")
})
observeEvent(input$lineupsandchampions, {
hide("trendsinperformance_panel")
hide("VsOpponent_panel")
show("lineupsandchampions_panel")
})
}
shinyApp(ui, server)
Related
I ran into a bit of trouble in my app. I have a fluidrow, which contains 2 colums, and these columns again contain fluid rows.
I have a textinput in the left column and a selectInput (with selectize = TRUE) on the right side.
While the contents of that row are on exactly one level, the contents of the next row are sadly pushed further down. This only happens with a selectInput in that location, so I assume that it has a larger margin below than for example a textInput.
I hope somebody had a similar problem an a solution before!
edit:
fluidRow(
column(
width = 4,
offset = 2,
h3("Unsere Kontaktdaten"),
fluidRow(
column(
width = 12,
disabled(
textInput(
inputId = "Kontakt",
label = "Firma",
value = "Digitale Giganten",
width = "100%"
)
),
)
),
fluidRow(
column(
width = 9,
disabled(
textInput(
inputId = "unsere_straße",
label = "Straße",
value = "Mohnstraße",
width = "100%"
)
),
),
column(
width = 3,
disabled(
textInput(
inputId = "unsere_hausnummer",
label = "Hausnummer",
value = 123,
width = "100%"
)
),
)
),
),
column(
width = 4,
offset = 1,
h3("Ansprechpartner"),
fluidRow(
column(
width = 3,
disabled(
selectInput(
inputId = "unsere_anrede",
label = "Anrede",
choices = c("Herr", "Frau", "Divers"),
width = "100%" )
)
),
column(
width = 9,
disabled(
textInput(
inputId = "unser_ansprechpartner",
label = "Ansprechpartner",
width = "100%",
value = "name"
)
)
)
),
disabled(
textInput(
inputId = "unsere_nummer",
label = "Telefon",
width = "100%",
value = 123456789
)
),
)
),
You can fix this via css. I wrapped the selectinput in a div() to style it:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
width = 4,
offset = 2,
h3("Unsere Kontaktdaten"),
fluidRow(
column(
width = 12,
disabled(
textInput(
inputId = "Kontakt",
label = "Firma",
value = "Digitale Giganten",
width = "100%"
)
),
)
),
fluidRow(
column(
width = 9,
disabled(
textInput(
inputId = "unsere_straße",
label = "Straße",
value = "Mohnstraße",
width = "100%"
)
),
),
column(
width = 3,
disabled(
textInput(
inputId = "unsere_hausnummer",
label = "Hausnummer",
value = 123,
width = "100%"
)
),
)
),
),
column(
width = 4,
offset = 1,
h3("Ansprechpartner"),
fluidRow(
column(
width = 3,
disabled(
div(selectInput(
inputId = "unsere_anrede",
label = "Anrede",
choices = c("Herr", "Frau", "Divers"),
width = "100%"),
style = "margin-bottom: -5px;")
)
),
column(
width = 9,
disabled(
textInput(
inputId = "unser_ansprechpartner",
label = "Ansprechpartner",
width = "100%",
value = "name"
)
)
)
),
disabled(
textInput(
inputId = "unsere_nummer",
label = "Telefon",
width = "100%",
value = 123456789
)
),
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
If you have multiple selectInputs you need to style and don't want to wrap each in a div, you can add:
tags$style("
.selectize-input {
margin-bottom: -5px !important;
}
")
somewhere in your UI.
I'm creating a table that has 88 columns, so naturally I'd require a scrollbar, I'd also like to highlight some column variables depending on their values, however my issue is that no horizontal scrollbar appears. This is the code:
library(DT)
library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(shinyjs)
data <- read.csv("somedata.csv", check.names = FALSE)
options(DT.options = list(pageLength = 5), scrollX = TRUE)
ui <- dashboardPage(
dashboardHeader(title = "Table Summary"),
dashboardSidebar(collapsed = FALSE,
sidebarMenu(
id = "tabs",
menuItem(text = "Tab 1",
tabName = "t1",
icon = icon('trophy'),
selected = TRUE
)
)
),
dashboardBody(
shinyjs::useShinyjs(),
tabItems(
tabItem(
tabName = "t1",
#we wan to create 3 separate pages on this tab
tabsetPanel(
id = "t1Selected", #returns value of current page we're on,
type = "tabs",
tabPanel(
title = "totals",
id = "tab_totals",
fluidRow(
column(width = 6, align = "right", DT::dataTableOutput("table"))
#DT::dataTableOutput("table")
),
fluidRow(
column(
width = 3, align = "left", checkboxInput("bt1", "Test for this?", TRUE)
),
column(
width = 3, align = "left",numericInput("bt1C", "Choice", 0, min = -100, max = 100)
),
column(
width = 3, align = "left", checkboxInput("bt2", "Test for this?", TRUE)
),
column(
width = 3, align = "left",numericInput("bt2C", "Choice", 0, min = -100, max = 100)
),
)
)
)
)
)
)
)
server <- function(input, output, session) {
observe({
shinyjs::enable("bt1C")
if(input$bt1 == 0){
shinyjs::disable("bt1C")
}
})
output$table <- DT::renderDataTable({
datatable(data) %>% formatStyle('Message_ratio', backgroundColor = styleEqual(c(0, 9.57), c('gray', 'yellow')))
})
}
shinyApp(ui, server)
I have the global setting for DT.options saying that scrollX should be on, but no horizontal taskbar comes up....
If it matters, I'm using windows.
Any suggestions would be helpful.
Before anyone recommends this link: How to make the horizontal scrollbar visible in DT::datatable
I've already tried what theyre saying, did not seem to help.
Using mtcars as example this works for me to get a horizontal scroll bar.
library(DT)
library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(shinyjs)
data <- mtcars
ui <- dashboardPage(
dashboardHeader(title = "Table Summary"),
dashboardSidebar(collapsed = FALSE,
sidebarMenu(
id = "tabs",
menuItem(text = "Tab 1",
tabName = "t1",
icon = icon('trophy'),
selected = TRUE
)
)
),
dashboardBody(
shinyjs::useShinyjs(),
tabItems(
tabItem(
tabName = "t1",
#we wan to create 3 separate pages on this tab
tabsetPanel(
id = "t1Selected", #returns value of current page we're on,
type = "tabs",
tabPanel(
title = "totals",
id = "tab_totals",
fluidRow(
column(width = 6, align = "right", DT::dataTableOutput("table"))
#DT::dataTableOutput("table")
),
fluidRow(
column(
width = 3, align = "left", checkboxInput("bt1", "Test for this?", TRUE)
),
column(
width = 3, align = "left",numericInput("bt1C", "Choice", 0, min = -100, max = 100)
),
column(
width = 3, align = "left", checkboxInput("bt2", "Test for this?", TRUE)
),
column(
width = 3, align = "left",numericInput("bt2C", "Choice", 0, min = -100, max = 100)
),
)
)
)
)
)
)
)
server <- function(input, output, session) {
observe({
shinyjs::enable("bt1C")
if(input$bt1 == 0){
shinyjs::disable("bt1C")
}
})
output$table <- DT::renderDataTable({
datatable(data, options = list(scrollX = TRUE)) %>%
formatStyle('mpg', backgroundColor = styleEqual(c(0, 9.57), c('gray', 'yellow')))
})
}
shinyApp(ui, server)
I'm trying to reduce the margin between two elements on this shiny app. When open in a browser, the whitespace between the two is huge.
I tried setting the css by adding style = "margin:0px; padding:0px" to the UI, but it did not help. I also tried messing with the inline = TRUE settings, also no help.
ui <- fluidPage(
fluidRow(
column(width = 3,
htmlOutput("select1", inline = TRUE, style = "margin:0px; padding:0px")
),
column(width = 3,
htmlOutput("select2", inline = TRUE, style = "margin:0px; padding:0px")
),
column(width = 6)
)
)
server <- function(input, output, session) {
output$select1 <- renderUI({
pickerInput(
inputId = "select1",
label = "LETTERS",
#choices = sort(unique(inventory$SubDivision)),
choices = LETTERS,
options = list(
"actions-box" = TRUE,
size = 10,
`live-search`=TRUE
),
multiple = TRUE
)
})
output$select2 <- renderUI({
pickerInput(
inputId = "select2",
label = "letters",
#choices = sort(unique(inventory$SubDivision)),
choices = letters,
options = list(
"actions-box" = TRUE,
size = 10,
`live-search`=TRUE
),
multiple = TRUE
)
})
}
shinyApp(ui, server)
Whitespace in browser:
The issue here is not the margin or padding, but the limit of the width to 300px. To allow the control to grow to full size of the column, you can change the global style :
ui <- fluidPage(
fluidRow(
tags$head(
tags$style(HTML("
.shiny-input-container:not(.shiny-input-container-inline) {
width:100%;
}"))
),
column(width = 3,
htmlOutput("select1", inline = TRUE)
),
column(width = 3,
htmlOutput("select2", inline = TRUE)
),
column(width = 6)
)
)
I recently discovered flipbox, an excellent UI on shinydashboardPlus(version 2.0.0). I want to insert numericinput in the front, but every time I click the input, it flips. Is it possible to make the flip executed only on the actionbutton?
example img
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
column(
width = 12,
uiOutput("active_side"),
actionButton("toggle", "Toggle flip box"),
flipBox(
id = "myflipbox",
trigger = "click",
width = 12,
front = div(
class = "text-center",
h1("Flip on click"),
numericInput("obs", "Observations:", 10, min = 1, max = 100)
),
back = div(
class = "text-center",
height = "300px",
width = "100%",
h1("Flip on hover"),
p("More information....")
)
)
)
)
)
),
server = function(input, output, session) {
observeEvent(input$toggle, {
updateFlipBox("myflipbox")
})
}
)
I have an shinydashboard app, the app get an filter box and a tabset which show a datatatable depending on filter.
I have a reset button which reset the filters whith shinyjs::reset function, and I want to reset also the tableset and showing the complete table or nothing.
I want also to do it for a valuboxes.
My app is like this :
For server interface I have an basic : output$tableprint_A <- DT::renderDataRable ({})
ui :
body <- dashboardBody(
tabItems(
#### First tab item #####
tabItem(tabName = "fpc",
fluidRow(
infoBoxOutput("kpm_inf", width = 6),
infoBoxOutput(outputId = "fpc_inf", width = 6)
),
fluidRow(
box(title = "Variables filter",
shinyjs::useShinyjs(),
id = "side_panel",
br(),
background = "light-blue",
solidHeader = TRUE,
width = 2,
selectInput("aaa", "aaa", multiple = T, choices = c("All", as.character(unique(fpc$aaa))))
br(),
br(),
p(class = "text-center", div(style = "display:inline-block", actionButton("go_button", "Search",
icon = icon("arrow-circle-o-right"))),
div(style = "display:inline-block", actionButton("reset_button", "Reset",
icon = icon("repeat")))),
p(class = 'text-center', downloadButton('dl_fpc', 'Download Data'))),
tabBox(
title = tagList(),
id = "tabset1",
width = 10,
tabPanel(
"A \u2030 ",
DT::dataTableOutput("tableprint_A"),
bsModal(id = 'startupModal', title = 'Update message', trigger = '',
size = 'large',
tags$p(tags$h2("Last update of A : 01/09/2017",
br(), br(),
"Last update of B : 01/09/2017",
br(), br(),
"Last update of C : 01/09/2017",
style = "color:green", align = "center")))
),
tabPanel(
"B % Table",
DT::dataTableOutput("tableprint_B")),
type = "pills"
)
),
fluidRow(
# Dynamic valueBoxes
valueBoxOutput("info_gen", width = 6)
)
I tried this :
observeEvent(input$reset_button, {
output$tableprint_A <- NULL
})
Edit:
I want something like that, but when I action the search button I want it to appear again :
shinyjs::onclick("reset_button",
shinyjs::toggle(id = "tableprint_A", anim = TRUE))
You should try this out:
output$tableprint_A <- renderDataTable({
if(input$reset_button == 1) {
NULL
}else{
datatable(...)
}
})
if the button is clicked then nothing will be displayed, else the datatable is shown.
[EDIT]
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(selectInput("select", "select", choices = unique(iris$Species), multiple = T),
actionButton("go_button", "Search",
icon = icon("arrow-circle-o-right")),
actionButton("reset_button", "Reset",
icon = icon("repeat")),
DT::dataTableOutput('tbl')),
server = function(input, output) {
values <- reactiveValues(matrix = NULL)
observe({
if (input$go_button == 0)
return()
values$matrix <- iris[iris$Species %in% input$select, ]
})
observe({
if (input$reset_button == 0)
return()
values$matrix <- NULL
})
output$tbl = DT::renderDataTable({
datatable(values$matrix, options = list(lengthChange = FALSE))}
)
}
)