Create 2 sidebar panels stacked vertically, one with tabs, one without - r

I would like to have a sidebar panel with tabs, while it also has a shared element that doesn't change if you click the tabs.
Intuitively, this could be achieved if the sidebar panel could be split into 2 pieces where the upper has the tabsetPanel, and bottom the shared element, but I can't find anything that allows this. (e.g. pageWithSidebar ( headerPanel(), sidebarPanel(tabsetPanel()),sidebarPanel(),mainPanel())
Is this possible?
e.g. this gives me 2 sidebars next to each other and a main panel underneath the second:
library(shiny)
ui <- fluidPage(
sidebarPanel(
tabsetPanel(
tabPanel("analysis-settings1",
textInput("settings1",label = "set some options")),
tabPanel("analysis-settings2",
textInput("settings2",label = "Some other settings"))
)),
sidebarPanel(
actionButton(inputId = "go", label="Go"),
verbatimTextOutput("showsummarysettings")),
mainPanel("..")
)
server <- function(input, output) {
observeEvent(input$go, ignoreInit=TRUE, {
output$showsummarysettings <- renderText({
"analysis-settings1 include ... and analysis-settings2 include ..."
})
})
}
# Run the app ----
shinyApp(ui = ui, server = server)

Please let me know if this doesn't solve your problem:
library(shiny)
ui <- fluidPage(
sidebarPanel(
tabsetPanel(
tabPanel("analysis-settings1",
textInput("settings1",label = "set some options")),
tabPanel("analysis-settings2",
textInput("settings2",label = "Some other settings"))
),
actionButton(inputId = "go", label="Go"),
verbatimTextOutput("showsummarysettings")),
mainPanel("..")
)
server <- function(input, output) {
observeEvent(input$go, ignoreInit=TRUE, {
output$showsummarysettings <- renderText({
"analysis-settings1 include ... and analysis-settings2 include ..."
})
})
}
# Run the app ----
shinyApp(ui = ui, server = server)

Related

Display and hide actionButton based on 2 other actionButtons

Below I press the first actionButton() "Show" to display another actionButton() but I would like also a second actionButton() named "Hide" that will hide the actionButton() that is displayed after clicking the "Show".
library(shiny)
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("button1", label = "Show"),
actionButton("button1b", label = "Hide")
),
mainPanel(
# what should I write here?
uiOutput("button2")
)
)
))
server = shinyServer(function(input, output, session) {
observeEvent(input$button1, {
output$button2 <- renderUI({
actionButton("button2", label = "Press Button 2")
})
})
})
shinyApp(ui = ui, server = server)
One option is to put the second button inside a conditionalPanel and set a toggle to display/hide the panel. See working code below.
library(shiny)
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("button1", label = "Show"),
actionButton("button1b", label = "Hide")
),
mainPanel(
# what should I write here?
conditionalPanel(condition = "output.display",
actionButton("button2", label = "Press Button 2"))
)
)
))
server = shinyServer(function(input, output, session) {
r <- reactiveValues(
toggle = NULL
)
observeEvent(input$button1, {
r$toggle = 1
})
observeEvent(input$button1b, {
r$toggle = 0
})
output$display <- reactive({
r$toggle
})
outputOptions(output, "display", suspendWhenHidden = FALSE)
})
shinyApp(ui = ui, server = server)
Another option is to dynamically insert and remove UI elements. But that option requires creation/destruction of UI elements every time the buttons are clicked. See example here

Disable and enable actionButton() by pushing another actionButton() in a shiny app

I have the shiny app below with 2 actionButton(). I want when I press Datatable the Datatable2 to be disabled and when I click again on Datatable the Datatable2 to be available for pressing again.
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("exc","Datatable"),
actionButton("exc2","Datatable2")
),
mainPanel(
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
This is really straightforward if you use the toggleState() function from the shinyjs package.
The help for that function gives you an extremely similar situation. In your case:
library(shiny)
ui <- fluidPage(
useShinyjs(), #this activates shinyjs
sidebarLayout(
sidebarPanel(
actionButton("exc","Datatable"),
actionButton("exc2","Datatable2")
),
mainPanel(
)
)
)
server <- function(input, output) {
observeEvent(input$exc, {
toggleState("exc2") #identify the element to toggle between active/inactive
})
}
shinyApp(ui = ui, server = server)

How to add a button to an item in a to do list in shiny

I am using shinydashboardplus.
I'd like to use the to do list but the example in the gallery is limited to just showing a list without any functionality.
To track a todo list for a user I am reading and writing to a csv for the moment.
I can read the csv to dynamically populate the list. Now I'd like to be able to strike through an item to indicate it is completed using the checked parameter.
The checked items should be removed from the csv.
Ill work on the adding items another day I think....
Here is my example (not reading from csv but from iris for this example).
library(shiny)
library(shinydashboardPlus)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
useShinydashboardPlus(),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
box(
"Sortable todo list demo",
status = "warning",
todoList(
apply(mtcars,1, function(x)
todoListItem(
label = x[1],
x[2]
)
)
)
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
Here is an approach using renderUI and a reactive data.frame:
library(shiny)
library(shinydashboardPlus)
library(shinyWidgets)
css <- "
.inlinecheckbox .shiny-input-container {
display: inline-block;
width: auto;
}
"
ui <- fluidPage(
tags$style(css),
titlePanel("Dynamic to do list"),
useShinydashboardPlus(),
sidebarLayout(
sidebarPanel(),
mainPanel(
box(
"Sortable todo list demo",
status = "warning",
uiOutput("myToDoList")
)
)
)
)
checkboxIDs <- paste0("checkbox", seq_len(nrow(mtcars)))
mtcars$checked <- FALSE
# Define server logic required to draw a histogram
server <- function(input, output) {
reactiveMtcars <- reactiveVal(mtcars)
observe({
for (i in seq_along(checkboxIDs)) {
if(!is.null(input[[checkboxIDs[1]]])){
mtcars$checked[i] <- input[[checkboxIDs[i]]]
}
}
reactiveMtcars(mtcars)
})
output$myToDoList <- renderUI({
req(reactiveMtcars())
todoListItems <- list()
for(i in seq_len(nrow(reactiveMtcars()))){
todoListItems[[i]] <- todoListItem(
label = div(rownames(reactiveMtcars())[i], style = ""),
span(class = "inlinecheckbox", checkboxInput(inputId = paste0("checkbox", i), label = NULL, value = reactiveMtcars()$checked[i])),
checked = reactiveMtcars()$checked[i],
)
}
todoList(todoListItems)
})
}
shinyApp(ui = ui, server = server)

Show box only when tableoutput is ready in shiny app

I want to generate a boxPlus around my DT-Output. Now when I start my APP, the frame of the box is already there. How do I manage that the box is only displayed when the tableoutput is finished? As input I use a text input.
In my UI I use for the Input:
textInput("name", "Insert Number:")
the final box I create with:
uiOutput("box")
On Serverside I do:
output$name <- renderText(input$name)
New_input <- reactive({
list(input$name)
})
and the box I create like this:
output$box <- renderUI({
boxPlus(
div(style = 'overflow-x: scroll;'), dataTableOutput("table")
)
})
I tried it with: Similar Problem but I can not resolve the problem. Without the box everything works fine.
Never use reactive expressions inside a renderText function.
You have to wrap tagList around your two elements to return a SINGLE element (a list in your case).
Here is a reproduceable example.
library(shiny)
library(shinydashboardPlus)
library(dplyr)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Hide box"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("name", "Insert Number to filter cyl:")
),
mainPanel(
uiOutput("box")
)
)
)
server <- function(input, output) {
resultdf <- reactive({
mtcars %>%
filter(cyl > input$name)
})
output$box <- renderUI({
output$table <- renderDataTable({
resultdf()
})
if(input$name == "") {
return(NULL)
} else {
return(
tagList(
boxPlus(
div(style = 'overflow-x: scroll;'), dataTableOutput("table")
)
)
)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)

widget example of actionbutton in shiny doesn't work

I'm playing around with shiny, and can't get the simplest action button example to work.
First example found here:http://shiny.rstudio.com/gallery/widgets-gallery.html
Below are the code, which is a copy paste from the website.
#ui.R
shinyUI(fluidPage(
# Copy the line below to make an action button
actionButton("action", label = "Action"),
hr(),
fluidRow(column(2, verbatimTextOutput("value")))
))
#server.R
shinyServer(function(input, output) {
# You can access the value of the widget with input$action, e.g.
output$value <- renderPrint({ input$action })
})
Mine looks like:
http://imgur.com/t0Vx6Wr
edit:
The issue is that it also prints out some class information
Thanks
Use renderText rather then renderPrint if you want it to look like it does on the shiny website:
require(shiny)
runApp(list(ui = fluidPage(
actionButton("action", label = "Action"),
hr(),
fluidRow(column(2, verbatimTextOutput("value")))
)
, server = function(input, output) {
output$value <- renderText({ input$action })
})
)

Resources