Is there a R function to adjust the title " Factors under the dataset " and "Numbers under the dataset". Below is the code I have tried. So I need the title at the middle of the grey coloured bar
library(shiny)
ui <- fluidPage(
tabsetPanel(tabPanel(
"Factor_Univariate_Analysis",sidebarLayout(
sidebarPanel(
column(h6(selectInput("se1","Factors under the dataset",choices =
c("","Add","sub"))),width = 11,height= 20,offset = 0),width = 1000),
mainPanel(h5(plotOutput("Plot1",width = 1000,height = 1500)))
)
),
tabPanel(
"Numeric_Univariate_Analysis",sidebarLayout(
sidebarPanel(
column(h6(selectInput("se2","Numbers under the dataset",choices =
c("","mean","median","standard_deviation","Data Distribution"))),width
= 11,height= 20,offset = 0),width = 1000),
mainPanel(h5(plotOutput("Plot2",width = 1500,height = 500)))
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Here is some code which I think is close to what you want to do, I'll just explain a few things first:
I have five years experience as a web developer, so I enjoy using CSS, and I would recommend using it where ever possible. What I beleive you were trying to do is give the label a background, this can be done with CSS. In this case I have put it in the style and html tags. label {} applies styles to all labels. You might want to agust the background color.
I have removed the side panel layouts.
Hopefully you find this helpful.
library(shiny)
ui <- fluidPage(
tags$style(HTML("
label {
width: 100%;
background: lightgrey;
padding: 5px;
border-radius: 5px;
}
")),
tabsetPanel(
tabPanel(
"Factor_Univariate_Analysis",
div(
column(width = 12,
h6(
selectInput(
"se1",
label = "Factors under the dataset",
choices = c("","Add","sub"),
width = "100%"
)
)
),
div(plotOutput("Plot1",width = 1000,height = 1500))
)
),
tabPanel(
"Numeric_Univariate_Analysis",
column(width = 12,
h6(
selectInput(
"se2",
"Numbers under the dataset",
choices = c("","mean","median","standard_deviation","Data Distribution"),
width = "100%"
)
)
),
div(plotOutput("Plot2",width = 1500,height = 500))
)
)
)
server <- function(input, output, session) {
observe({
print(input$se1)
updateSelectInput(session, input$se1, label = "Factors under the dataset replaced")
})
}
# https://shiny.rstudio.com/reference/shiny/latest/updateSelectInput.html
shinyApp(ui, server)
Related
I have the following code to build a Shinydashboard app. I'm trying to change the background color in the box on the top of my screen to a custom color (a color hex code color), however the options for the argument background only allow for a set of default colors. Is there a way to change the background color of this box specifically while keeping the white background for the remainder of my boxes?
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = 'Dashboard'),
dashboardSidebar(sidebarMenu
(menuItem(tabName = 'Panel1', text = 'Panel 1'),
dateInput("Start_Date", "Start Date", min = '2000-01-01', max = Sys.Date(), value = '2020-01-01',format = "yyyy-mm-dd")
)
),
dashboardBody(
tabItems(tabItem(tabName = 'Panel1',
fluidRow(box(selectizeInput('select_mean', 'Select Number',
choices = c(12,24,36,48,60,120)),height=80,width=4,
background = 'black')),
fluidRow(box(width = 13, height = 655))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
You can use htmltools::tagQuery to add a style:
library(htmltools)
library(shinydashboard)
library(shiny)
b <- box(selectInput("id", "label", c("a", "b", "c")))
b <- tagQuery(b)$find(".box")$addAttrs(style = "background-color: pink;")$allTags()
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(b)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
You can do the following steps :
put your box into a tags$div and give it an ID (here : "toto")
add some CSS to the box, which is two div childs after your div toto
You can also put the CSS in a separate file, see https://shiny.rstudio.com/articles/css.html
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = 'Dashboard'),
dashboardSidebar(sidebarMenu
(menuItem(tabName = 'Panel1', text = 'Panel 1'),
dateInput("Start_Date", "Start Date", min = '2000-01-01', max = Sys.Date(), value = '2020-01-01',format = "yyyy-mm-dd")
)
),
dashboardBody(
tags$head(
tags$style(HTML("
#toto > div:nth-child(1) > div:nth-child(1) {
background-color: rgb(128, 0, 0);
}"))),
tabItems(tabItem(tabName = 'Panel1',
fluidRow(
tags$div(
id = "toto",
box(selectizeInput('select_mean', 'Select Number',
choices = c(12,24,36,48,60,120)),height=80,width=4)
)
),
fluidRow(box(width = 13, height = 655))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
The reproducible code below uses a fluidRow() to house several user selections using radio buttons. Works fine in this limited example of only 2 radio button groupings. But I need to fit more radio button groupings into this row, without any wrapping. To do this, I'd like to replace this combination of fluidRow()/column() with a horizontally scrollable, non-wrapping row that is not subject to the limitations of the 12-wide grid system currently used in this code.
Also, all objects viewed in the scrolling row need to be left aligned without "fluid" expansion. Currently, using this fluidRow()/column() combo, if the viewing pane is expanded, the 2 columns housing each radio button grouping also expanded which doesn't look good. They need to remain fixed width and stay to the left.
Is this possible?
I prefer sticking with this sidebar/main panel/tab panel/conditional panel layout as I find it very user friendly for navigating the type of data we work with.
The image at the bottom further explains.
Reproducible code:
library(dplyr)
library(DT)
library(shiny)
library(shinyWidgets)
ui <-
fluidPage(
titlePanel("Summary"),
sidebarLayout(
sidebarPanel(
selectInput("selectData", h5("Select data to view:"),
choices = list("Beta"),
selected = "Beta"),
),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
conditionalPanel(condition = "input.selectData == 'Beta'",
fluidRow(div(style = "margin-top:15px"),
column(width = 6, offset = 0,
wellPanel(
radioButtons(inputId = 'group1',
label = NULL,
choiceNames = c('By period','By MOA'),
choiceValues = c('Period','MOA'),
selected = 'Period',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
),
column(width = 6, offset = 0,
wellPanel(
radioButtons(inputId = 'group2',
label = NULL,
choiceNames = c('Exclude CT','Include CT'),
choiceValues = c('Exclude','Include'),
selected = 'Exclude',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
)
),
DTOutput("plants")
)
),
id = "tabselected"
)
)
)
)
server <- function(input, output, session) {
output$plants <- renderDT({iris %>% datatable(rownames = FALSE)})
}
shinyApp(ui, server)
How about using a carousel instead e.g. via shinyglide or slickR:
library(dplyr)
library(DT)
library(shiny)
library(shinyWidgets)
library(shinyglide)
ui <-
fluidPage(
titlePanel("Summary"),
sidebarLayout(
sidebarPanel(
selectInput("selectData", h5("Select data to view:"),
choices = list("Beta"),
selected = "Beta"),
),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
conditionalPanel(condition = "input.selectData == 'Beta'",
fluidRow(div(style = "margin-top:15px"),
column(12, glide(
height = "25",
controls_position = "top",
screen(
p(strong("Group 1")),
wellPanel(
radioButtons(inputId = 'group1',
label = NULL,
choiceNames = c('By period','By MOA'),
choiceValues = c('Period','MOA'),
selected = 'Period',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
),
screen(
p(strong("Group 2")),
wellPanel(
radioButtons(inputId = 'group2',
label = NULL,
choiceNames = c('Exclude CT','Include CT'),
choiceValues = c('Exclude','Include'),
selected = 'Exclude',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
)
))
),
DTOutput("plants")
)
),
id = "tabselected"
)
)
)
)
server <- function(input, output, session) {
output$plants <- renderDT({iris %>% datatable(rownames = FALSE)})
}
shinyApp(ui, server)
I am trying to keep each number within its respective knobInput, regardless of zoom status or screen size. However, after zooming 120% or reducing the screen size, the number pops outside of its relative position.
library(shiny)
ui <- fluidPage(fluidRow(
column(2, uiOutput("example_1")),
column(2, uiOutput("example_2")),
column(2, uiOutput("example_3")),
column(2, uiOutput("example_4")),
column(2, uiOutput("example_5")),
column(2, uiOutput("example_6"))
)
)
server <- function(input, output, session) {
output$example_1 = output$example_2 = output$example_3 = output$example_4 = output$example_5 = output$example_6 = renderUI(knobInput(
inputId = "example_knob",
label = NULL,
value = 10,
fontSize = "2em"
))
}
shinyApp(ui, server)
Grateful for any advice as to how I could achieve this.
So ... The problem here is that you are not filling the horizontal space of your fluidrow which is 12 with your columns. Setting the columnwidth to 4 makes it work:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(fluidRow(
column(4, uiOutput("example_1")),
column(4, uiOutput("example_2")),
column(4, uiOutput("example_3"))
)
)
server <- function(input, output, session) {
output$example_1 = output$example_2 = output$example_3 = renderUI(knobInput(
inputId = "example_knob",
label = NULL,
value = 10,
fontSize = "2em"
))
}
shinyApp(ui, server)
I am trying to make an xlsx sheet of customers orders of certain items. I created a shiny app to input each order in the form of a datatable row which is added to the table on click of "Add" Button. But I face a problem, each time I add a new order (row) an extra cell of row number is generated in all the previous ones like in the picture.
and all row cells are shifted to the right!!
This is my code:
library(shiny)
library(shinythemes)
library(readxl)
library(xlsx)
library(DT)
items <- read_excel("items.xlsx",col_names = F)
colnames(items) <- c("Items", "Euro", "Cost")
ui <- fluidPage(theme = shinytheme('journal'),
sidebarLayout(
sidebarPanel(
tags$img(height = 118, width = 160, src="logo.jpg"),
br(),br(),
textInput('name','Name'),
br(),
selectizeInput(inputId = "item",
label = "Item",
choices = c(items$Items),
options = list(
placeholder = '',
onInitialize = I('function() { this.setValue(""); }'))),
br(),
numericInput('number','Quantity',value = 1,step = 1),
br(),
numericInput('price','Price/pc',value = ''),
br(),
actionButton(inputId = "button", label = "Add", icon = icon("plus"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
width = 3),
mainPanel(DTOutput('out')))
)
server <- function(input, output,session) {
observeEvent(input$button,{
order <- data.frame(read_excel("Order.xlsx"))
price <- items[items$Items == input$item,][c(2,3)]
order[nrow(order) + 1,] <- c(ifelse(input$name %in% order$Name,'',input$name),input$item,input$number,
price,price[2]* input$number,input$price*input$number,
(input$price*input$number) - (price[2]* input$number))
write.xlsx(order,'order.xlsx')
output$out<- renderDT({datatable(order)})
})
}
shinyApp(ui = ui, server = server)
items.xlsx
Items Euro Cost
some item 2.5 10
some item2 5 20
some item3 4 18
order.xlsx
Name Item Quantity Euro Cost Total cost Total price Gain
can somebody know what is the cause for that and how to solve?
Thanks all
I couldn't recreate your exact app because I had trouble getting xlsx package to load on my system. I recreated a similar working example by saving the two excel files as CSV files and using readr read_csv and write_csv in place of your read_excel and write.xlsx. This version appears to work as you want it to but with csv output instead of excel. Having a read of the xlsx documentation I might have a guess that row names are being written out each time you write.xlsx and this is showing up when you read them back in. Could it be that you need to pass row.names = FALSE to your write.xlsx call?
https://cran.r-project.org/web/packages/xlsx/xlsx.pdf
library(shiny)
library(shinythemes)
library(DT)
library(readr)
items <- readr::read_csv("items.csv",col_names = T)
ui <- fluidPage(theme = shinytheme('journal'),
sidebarLayout(
sidebarPanel(
tags$img(height = 118, width = 160, src="logo.jpg"),
br(),br(),
textInput('name','Name'),
br(),
selectizeInput(inputId = "item",
label = "Item",
choices = c(items$Items),
options = list(
placeholder = '',
onInitialize = I('function() { this.setValue(""); }'))),
br(),
numericInput('number','Quantity',value = 1,step = 1),
br(),
numericInput('price','Price/pc',value = ''),
br(),
actionButton(inputId = "button", label = "Add", icon = icon("plus"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
width = 3),
mainPanel(DTOutput('out')))
)
server <- function(input, output,session) {
observeEvent(input$button,{
order <- data.frame(read_csv("order.csv"))
price <- items[items$Items == input$item,][c(2,3)]
order[nrow(order) + 1,] <- c(ifelse(input$name %in% order$Name,'',input$name),input$item,input$number,
price,price[2]* input$number,input$price*input$number,
(input$price*input$number) - (price[2]* input$number))
write_csv(order,'order.csv')
output$out<- renderDT({datatable(order)})
})
}
shinyApp(ui = ui, server = server)
Try to perform data reading and data wrangling outside of the observer as shown below.
items <- read.table(text='"Items","Euro","Cost"
some item, 2.5, 10
some item2, 5,20
some item3, 4,18', header=TRUE, sep=",")
ui <- fluidPage(theme = shinytheme('journal'),
sidebarLayout(
sidebarPanel(
tags$img(height = 118, width = 160, src="logo.jpg"),
br(),br(),
textInput('name','Name'),
br(),
selectizeInput(inputId = "item",
label = "Item",
choices = c(items$Items),
options = list(
placeholder = '',
onInitialize = I('function() { this.setValue(""); }'))),
br(),
numericInput('number','Quantity',value = 1,step = 1),
br(),
numericInput('price','Price/pc',value = ''),
br(),
actionButton(inputId = "button", label = "Add", icon = icon("plus"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
width = 3),
mainPanel(DTOutput('out')))
)
server <- function(input, output,session) {
order <- eventReactive(input$button,{
req(input$number,input$price,input$name)
order <- data.frame(read_excel("order.xlsx"))
price <- items[items$Items == input$item,][c(2,3)]
order[nrow(order) + 1,] <- c(ifelse(input$name %in% order$Name,'',input$name),input$item,input$number,
price,price[2]* input$number,input$price*input$number,
(input$price*input$number) - (price[2]* input$number))
order
})
observeEvent(input$button,{ write.xlsx(order(),'order.xlsx') })
output$out<- renderDT({datatable(order())})
}
shinyApp(ui = ui, server = server)
This is the problem I am trying to solve. My navbarpage overlaps other elements from below. Is there any way to put the navbarpage in the background? Or perhaps make the daterange input show it's calendar below its input box?
The documentation mentions using fixed-top or fixed-bottom for the posotion argument will cause the navbar to overlay your body content, unless you add padding.
Adding padding does not solve the problem though.
Here is a reproducible example -
ui <- fluidPage(
fluidRow(class = 'headerrow', column(width = 12, style = "font-size: 30pt; line-height: 8vh; text-align:left; color:#FFFFFF; width = 100", tags$strong('Test')), tags$head(tags$style('.headerrow{height:8vh; background-color:#267dff}'))),
navbarPage(
'Navbar',
tabPanel(
'Menu1',
sidebarPanel(
selectInput('drink', 'Choose your poison', choices = c('Bloody Mary', 'Sex on the beach'), selected = 'Bloody Mary'),
dateRangeInput('period', 'Date range', start = '2016-05-01', end = '2017-04-01',
min = '2013-07-01', max = '2017-06-01', startview = 'year', format = 'mm/yyyy'),
width = 2
),
mainPanel(width = 10)
),
tabPanel('Menu2'),
tabPanel('Menu3'),
tabPanel('Menu4')
)
)
server <- function(input, output){
}
shinyApp(ui, server)
Thank you so much!
Try adding z-index to the div: tags$style(HTML(".datepicker {z-index:99999 !important;}"))
library(shiny)
ui <- fluidPage(
fluidRow(class = 'headerrow', column(width = 12, style = "font-size: 30pt; line-height: 8vh; text-align:left; color:#FFFFFF; width = 100", tags$strong('Test')), tags$head(tags$style('.headerrow{height:8vh; background-color:#267dff}'))),
navbarPage(
'Navbar',
tabPanel(
'Menu1',
tags$style(HTML(".datepicker {z-index:99999 !important;}")),
sidebarPanel(
selectInput('drink', 'Choose your poison', choices = c('Bloody Mary', 'Sex on the beach'), selected = 'Bloody Mary'),
dateRangeInput('period', 'Date range', start = '2016-05-01', end = '2017-04-01',
min = '2013-07-01', max = '2017-06-01', startview = 'year', format = 'mm/yyyy'),
width = 2
),
mainPanel(width = 10)
),
tabPanel('Menu2'),
tabPanel('Menu3'),
tabPanel('Menu4')
)
)
server <- function(input, output){}
shinyApp(ui, server)