How can I show the text of the first two rows in a renderTable in bold? Can I do this without DT/renderDataTable?
How about this:
shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML("tr:first-child, tr:first-child + tr { font-weight: bold }")
)
),
fluidRow(
column(12, tableOutput('table')
)
)
),
server = function(input, output) {
output$table <- renderTable(head(iris))
}
)
Try this:
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(
"tr:nth-child(1) {font-weight: bold;}
tr:nth-child(2) {font-weight: bold;}
"
)
),
tableOutput("tbl")
)
server <- function(input, output){
output$tbl <- renderTable({iris})
}
shinyApp(ui, server)
Related
Is there anyway to change the fill colour of the verbatimTextOutput? Basically I want this to stand out from the other sections. The below is an illustration figure to show why it doesn't stand out with the default settings. And at the bottom is a simple example with 1 verbatimTextOutput
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
verbatimTextOutput("test"),
width = 2
),
mainPanel(
"",
width = 8
))
)
server <- function(input, output, session) {
output$test = renderText("Hi")
}
shinyApp(ui, server)
You can have your custom CSS for the pre elements (verbatimTextOutput). You can add CSS as .css file or inline. Below is an example using an inline CSS.
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(HTML("
/* this will affect all the pre elements */
pre {
color: red;
background-color: #5ef4fb;
}
/* this will affect only the pre elements under the class myclass */
.myclass pre {
color: black;
background-color: #d6860f;
font-weight: bolder;
}"))
),
sidebarLayout(
sidebarPanel(
verbatimTextOutput("test1"),
div(class = "myclass",
verbatimTextOutput("test2")
),
width = 2
),
mainPanel(
"",
width = 8
))
)
server <- function(input, output, session) {
output$test1 = renderText("Hi")
output$test2 = renderText("Hello")
}
shinyApp(ui, server)
What I am trying to do is to use an if statement to prevent 'Analyse' button to perform an action twice, I want to disable the button when the button is clicked on one selection once already.
I have simplified the code to isolate the if statement area. Anyone know what's going on here? Thanks
library(shiny)
library(shinyjs)
ui <- fluidPage(
navbarPage(title = "Test",
tabPanel("Home",
sidebarPanel(
actionButton("append", "Analyse")
),
mainPanel()
)
)
)
server <- function(input, output, session) {
observeEvent(input$append,{
disbut<-1
if(disbut==1)
{
disable("append")
}
else {
enable("append")
}
})
}
shinyApp(ui, server)
You have to call useShinyjs() in the ui as shown below.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
navbarPage(title = "Test",
tabPanel("Home",
sidebarPanel(
actionButton("append", "Analyse")
),
mainPanel()
)
)
)
server <- function(input, output, session) {
observeEvent(input$append,{
disbut<-1
if(disbut==1)
{
shinyjs::disable("append")
}
else {
shinyjs::enable("append")
}
})
}
shinyApp(ui, server)
You have to initialise shinyjs with useShinyjs()
ui <- fluidPage(
useShinyjs(),
navbarPage(title = "Test",
tabPanel("Home",
sidebarPanel(
actionButton("append", "Analyse")
),
mainPanel()
)
)
)
Wanted to check if we can highlight the active tabs . i mean when the user is in one tab ("agh"), that tab should be underlined. Similarly for other tab as well. Reprex below
app.R
library(shiny)
shinyApp(
navbarPage(
tags$head(
tags$style(
HTML(".tabbable > .nav > li[class=active] > a {text-decoration: underline}")
)
),
tabPanel("Tab1"),
tabPanel("Tab2"),
tabsetPanel(
tabPanel("agh",
numericInput("n", "Number to add", 5),
actionButton("add", "Add"),
verbatimTextOutput("sum", placeholder = TRUE)
),
tabPanel("dfd")
)
),
function(input, output, session) {
nums <- numeric()
c_sum <- eventReactive(input$add, {
nums <<- c(nums, input$n)
sum(nums)
})
output$sum <- renderText({
c_sum()
})
}
)
library(shiny)
shinyApp(
fluidPage(
tags$head(
tags$style(
HTML(".tabbable > .nav > li[class=active] > a {text-decoration: underline}")
)
),
br(),
tabsetPanel(
tabPanel("agh",
numericInput("n", "Number to add", 5),
actionButton("add", "Add"),
verbatimTextOutput("sum", placeholder = TRUE)
),
tabPanel("dfd")
)
),
function(input, output, session) {
nums <- numeric()
c_sum <- eventReactive(input$add, {
nums <<- c(nums, input$n)
sum(nums)
})
output$sum <- renderText({
c_sum()
})
}
)
Can anyone help with setting the top/bottom margin for the tabs in a tabsetPanel in shiny using CSS?
Here's an example code
library(shiny)
shinyApp(
ui=shinyUI(
fixedPage(
tabsetPanel(
tabPanel("Data Input",
fixedRow(
column(12,
h6("test"))
)
)
)
)
)
,
server=shinyServer(function(input, output) {
})
)
Maybe something like this. For more info see: Background color of tabs in shiny tabPanel
library(shiny)
shinyApp(
ui=shinyUI(
fixedPage(
tabsetPanel(
tabPanel("Data Input",
tags$style(HTML("
.tabbable > .nav > li > a {margin-top:50px;}")),
fixedRow(
column(12,
h6("test"))
)
)
)
)
)
,
server=shinyServer(function(input, output) {
})
)
I've got a shiny application like this:
server.R:
library(shiny)
function(input, output) { NULL }
and ui.R:
library(shiny)
pageWithSidebar(
headerPanel("side-by-side"),
fluidRow(
column(2),
column(4,
wellPanel(
selectInput(inputId = "options", label = "some text",
choices = list(a = 0, b = 1)))
)
),
fluidRow(
h3("bla bla")
)
)
And I would like to have the label of selectInput next to it, not above. Do you know how to do it?
I've found this: Positioning Shiny widgets beside their headers
but it doesn't work for me.
There's multiple ways of doing this, here's one:
library(shiny)
server <- shinyServer(function(input, output) { NULL })
ui <- shinyUI(
pageWithSidebar(
headerPanel("side-by-side"),
sidebarPanel(
fluidRow(
tags$head(
tags$style(type="text/css", "label.control-label, .selectize-control.single{ display: table-cell; text-align: center; vertical-align: middle; } .form-group { display: table-row;}")
),
column(2),
column(4,
selectInput(inputId = "options", label = "some text",
choices = list(a = 0, b = 1))
)
)),
mainPanel(
fluidRow(
h3("bla bla")
))
)
)
shinyApp(ui=ui,server=server)
If you don't want to mess with shinys default CSS you can just leave the label empty and create a label next to it instead of forcing the existing label to the side.