putting date range to pdf in shiny app - r

I have an app which looks like below:enter image description here
I would like to download datatable to pdf with that time period. but when i do it only table exports. enter image description here
here is ma ui.R code:
library(shiny)
jscode <- "shinyjs.closeWindow = function() { window.close(); }"
shinyUI(fluidPage(
tags$head(
tags$style(HTML("
#import url('//fonts.googleapis.com/css?family=Anton');
h2 {
font-family: 'Anton';
font-weight: 600;
line-height: 0.7;
color: #483D8B;
}
"))
),
titlePanel("ZESTAWIENIE 1 v 2"),
sidebarLayout(
sidebarPanel( tags$head(
tags$style(type="text/css", ".well { width: 150px; }"),
tags$style(type="text/css", ".col-sm-4 { width: 170px;}"),
# tags$style(type="text/css", "#close {font-size: 12px; background-color: #e6e6e6; }") ,
tags$style(type="text/css", "#get_data { font-size: 12px; background-color: #e6e6e6;}") ,
tags$style(type="text/css", "#last_month { font-size: 12px;background-color: #e6e6e6; }") ,
tags$style(type="text/css", ".control-label { line-height: 2 ; font-size: 12px; }") ,
tags$style(type="text/css", "#text { width: 390px ; font-size: 11px } "),
tags$style(type="text/css", "#DataTables_Table_0 td[text*='SAL']{ background:#DCDCDC; }")
),
# actionButton("close", "Zamknij raport" ,width = '100%' ),
actionButton("get_data", "Generuj report" ,width = '100%' ),
actionButton("last_month", "Ostatni miesiÄ…c", width = '100%' ),
dateInput('start_date', "Data poczÄ…tkowa", min = '2017-11-01', value= format(Sys.Date()-1, "%Y-%m-01")),
dateInput('end_date', "Data końcowa", min = '2017-11-01' ,value= format(Sys.Date()-1, "%Y-%m-%d"))
),
mainPanel(tags$head(
tags$style(type="text/css", ".col-sm-8 { width: 89%; }")
),
div(
verbatimTextOutput("text"), DT::dataTableOutput("results"), style = "font-size:80%" ),
tabsetPanel(
tabPanel(
HTML('<footer>
<h6> kontakt: kk </h6>
</footer>')
))
)
)
))
where shloud I put verbatimTextOutput("text") which is responsible for showing date range to have that date if pdf after downloading?

You can use caption
library(shiny)
library(DT)
ui <- fluidPage(
dateRangeInput("daterange1", "Date range:",
start = "2001-01-01",
end = "2010-12-31"),
DT::dataTableOutput('table')
)
server <- function(input, output, session) {
output$table <- renderDataTable(
head(iris),
caption = paste("Report Data:", input$daterange1[1], "to", input$daterange1[2] ),extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('pdf')
))
}
shinyApp(ui, server)

Related

Is it possible to export a div having an id with all its contents using R & Shiny as done for example in javascript with JsPdf?

I know the question is a bit silly but hey it's worth it. Usually, when exporting files with datatables in R and Shiny it's quite easy but today I would like to be able to export all the content of a div which contains for example paragraphs, html tables and etc... without however losing the CSS, is it possible to do this with R and Shiny?
library(shiny)
#UI
ui = fluidPage(
downloadButton("download", "Print as pdf"),
fluidRow(
box(width = 12,id="PS1AGLOBAL",dataTableOutput("table_pse1aglobal"),title="",
collapsible = T,
fluidRow(
column(10, #wellPanel(p("Column width 8"))),
column(2,tags$p(style="position: relative; top: -15px;", "PSE 1A global"))),
fluidRow(
column(8, tags$p(style="text-decoration: underline; text-transform: capitalize; font-size: 20px; font-weight: bold; letter-spacing: 2px;", "DECLARATION")
),
column(4)
),
fluidRow(
uiOutput("generated_declaration")
),
)
#SERVER
server <- function(input, output, session) {
downloadHandler(
filename = function () {
#i don't know
}
)
}
shinyApp(ui, server)
I don't know if I have posed my problem correctly, but I just want to export the content of the div with the id "table_pse1aglobal" in a pdf file when a button is clicked. I am open to any suggestions thank you.
You can use the capture package.
library(shiny)
library(shinydashboard)
library(capture) # remotes::install_github("dreamRs/capture")
# UI
ui <- fluidPage(
capture::capture_pdf(
selector = "#PS1AGLOBAL",
filename = "box.pdf",
icon("camera"),
"Take PDF screenshot."
),
fluidRow(
box(
width = 12,
id = "PS1AGLOBAL",
h1("HELLO"),
title = "TITLE",
collapsible = TRUE,
fluidRow(
column(
10,
column(
2,
tags$p(style = "position: relative; top: -15px;", "PSE 1A global")
)
),
fluidRow(
column(
8,
tags$p(
style = "text-decoration: underline; text-transform: capitalize; font-size: 20px; font-weight: bold; letter-spacing: 2px;",
"DECLARATION"
)
),
column(4)
)
)
)
)
)
# SERVER
server <- function(input, output, session) {
}
shinyApp(ui, server)
This package is not on CRAN. Maybe shinyscreenshot can achieve the same result, and this package is on CRAN.
EDIT
Looks like that does not work well with the box, so put it inside a div:
fluidRow(
div(
id = "PS1AGLOBAL",
box(
width = 12,
h1("HELLO"),
title = "TITLE",
collapsible = TRUE,
fluidRow(
column(
10,
column(
2,
tags$p(style = "position: relative; top: -15px;", "PSE 1A global")
)
),
fluidRow(
column(
8,
tags$p(
style = "text-decoration: underline; text-transform: capitalize; font-size: 20px; font-weight: bold; letter-spacing: 2px;",
"DECLARATION"
)
),
column(4)
)
)
)
)
)

Clear textinput post clicking the button

Is there a way to clear the tectinput after clicking the button. I tried with below code but does not work.
Open the application and fill the textinput. But after clicking the button, it does not clear
library(shiny)
library(shinyjs)
runApp(
list(
ui = shinyUI(fluidPage(theme = "bootstrap.css",
fluidRow(
column(8, align="center", offset = 2,
# selectInput("sdf","Asdf", choices = c(1,2), selected = NULL),
textInput("string", label="Input",value = "", width = "100%"),
tags$style("#string { height: 50px; width: 100%; text-align:center; font-size: 15px; display: block;}")
)
),
fluidRow(
column(6, align="center", offset = 3,
actionButton("button",label = "Clear"),
tags$style(type='text/css', "#button { vertical-align: middle; height: 50px; width: 100%; font-size: 30px;}")
)
)
)
), server = shinyServer(function(input, output) {
observeEvent(input$button,{
shinyjs::runjs("document.getElementById('string').reset();")
})
})))
What about updateTextInput?:
library(shiny)
library(shinyjs)
runApp(list(ui = shinyUI(
fluidPage(theme = "bootstrap.css",
fluidRow(
column(
8,
align = "center",
offset = 2,
# selectInput("sdf","Asdf", choices = c(1,2), selected = NULL),
textInput(
"string",
label = "Input",
value = "",
width = "100%"
),
tags$style(
"#string { height: 50px; width: 100%; text-align:center; font-size: 15px; display: block;}"
)
)
),
fluidRow(
column(
6,
align = "center",
offset = 3,
actionButton("button", label = "Clear"),
tags$style(
type = 'text/css',
"#button { vertical-align: middle; height: 50px; width: 100%; font-size: 30px;}"
)
)
))
), server = shinyServer(function(input, output, session) {
observeEvent(input$button, {
updateTextInput(session, inputId = "string", value = "")
})
})))

fluidRow(column(3, : argument is missing, with no default

I try to run shiny app and get error:
fluidRow(column(3, : argument is missing, with no default
I have two tabPanel. I check code and there is no missing argument, no additional comma etc. when I run some portion of this code it works. I can't guess source of this error. How to deal with this problem?
Bellow you can see one part of UI-side code of this shiny app:
ui <- fluidPage(
theme = shinytheme("slate"),
tabsetPanel(
tabPanel(h4("TOP N' financial"),
fluidRow(
column(3,
selectInput("bank", "Choose Bank", choices = unique(BANKS$BANK)),
numericInput("Number", "Choose top N borrower", value = 10, min = 1),
tags$style(type='text/css', ".selectize-input { font-size: 10px; line-height: 1px;}
.selectize-dropdown { font-size: 10px; line-height: 10px; }"),
selectizeInput("excl","SELECT Columns", colname, multiple=T)
),
column(9,
div(dataTableOutput("topNtable"), style = "font-size: 75%; width: 75%")
)
),
br(),
fluidRow(style = "background-color:#4d3a7d;",
h4("Ratio Calculation and plotting"),
column(7,
style = "border: 4px ridge #01B392;",
fluidRow(
textInput("client_ID", "Insert Client ID", value = '204885044'),
uiOutput("ID_table")
),
fluidRow(style = "border: 4px ridge #FF8902;",
plotlyOutput('coef_plot'))
),
column(5,
style = "border: 4px double red;",
h4('simple calculator'),
fluidRow(
tags$style(type='text/css', ".selectize-input { font-size: 10px; line-height: 1px;}
.selectize-dropdown { font-size: 10px; line-height: 10px; }"),
column(6,
selectInput("num", "Numerator", num_cols, selected = 'TOTAL_ASSETS')),
column(6,
selectInput("denum", "denumerator", num_cols, selected = 'TOTAL_LIABILITIES'))
),
fluidRow(
column(6, align = "center",
div(tableOutput("coefficient"))#,style = "font-size: 75%; width: 75%")
)
)
)
),
This is server code (whole)
server <- function(input, output, session){
react_fin <- reactive(get_top_N_financial(input$bank,input$Number, input$excl)%>%
group_by(CLIENT_ID)%>%
filter(DATE == max(DATE))%>%
head(n=input$Number))
output$topNtable <- renderDataTable(react_fin())
#CALCULATOR
calc_d <- reactive(get_top_N_financial(input$bank,input$Number, c(num_cols,'DATE')))
coef_d <- reactive({
req(input$client_ID)
filter(calc_d(), CLIENT_ID == input$client_ID)
})
coef_df <- reactive({
req(input$num)
req(input$denum)
ratio <- round(coef_d()[[input$num]]/coef_d()[[input$denum]], 4)
data.frame(cbind(ratio, coef_d()$DATE))%>%
rename('Date'=V2)%>%
arrange(desc(Date))
})
output$coefficient <- renderTable(coef_df()%>%
slice_head(n = 6))
output$coef_plot <-renderPlotly(plot_ly(coef_df(), x = ~Date,
y = ~ratio, type = 'scatter', mode = 'lines',
height = 300, width = 500))
Client <- reactive((get_name(input$bank, input$client_ID)))
output$ID_table <- renderUI(Client()$CLIENT_NAME)
pd_dt <- reactive(get_debt(input$client_ID))
output$ecl_pl <- renderPlot(plot_pd_lgd(pd_dt()))
## create ind_table
observeEvent(pd_dt(), {
choices <- unique(pd_dt()$DATE)
updateSelectInput(inputId = "ind_date", choices = choices)
})
output$ind_table <-function()(ind_sum_tbl(pd_dt(), input$ind_date))
################# PAGE2 #################
d_PD_PTI <- reactive(get_PD_PTI(input$N, input$start, input$end, input$stage))
output$reg_pl <- renderPlot(PD_PTI_Bank(d_PD_PTI()))
d_PD_Box <- reactive(get_PD_Box(input$N,input$stage))
output$Box_pd <- renderPlot(PD_Box(d_PD_Box()))
output$PTI_PD <- renderPlot(PD_PTI_heat(d_PD_PTI()))
d_LGD_LTV <- reactive(get_LGD_LTV(input$N, input$start, input$end,input$stage))
output$LTV_LGD <- renderPlot(LGD_LTV_heat(d_LGD_LTV()))
output$PD_Client_scatter <- renderPlotly(PD_diff_banks_scatter(input$start, input$end, input$N))
df <- reactive(PD_CLIENT_DF(input$start, input$end,input$N))
output$PD_scat <- renderPlot(PD_CLIENT_plot(df()))
output$brush_tbl <-renderTable({
brushedPoints(df(), input$brush) %>%
select()
})
}
Thanks in advance
My guess: Issue of parentheses: Here is a working example with your UI code.
library(shiny)
library(shinythemes)
BANKS
ui <- fluidPage(
theme = shinytheme("slate"),
tabsetPanel(
tabPanel(h4("TOP N' financial"),
fluidRow(
column(3,
selectInput("bank", "Choose Bank", choices = unique(BANKS$BANK)),
numericInput("Number", "Choose top N borrower", value = 10, min = 1),
tags$style(type='text/css', ".selectize-input { font-size: 10px; line-height: 1px;}
.selectize-dropdown { font-size: 10px; line-height: 10px; }"),
selectizeInput("excl","SELECT Columns", colname, multiple=T)
),
column(9,
div(dataTableOutput("topNtable"), style = "font-size: 75%; width: 75%")
)
)
)
)
),
server <- function(input, output, session) {
}
shinyApp(ui, server)

R Shiny: Relative size of images with slickR

Using a Shiny app, I would like to implement a slider with slickR to switch from one image to the other.
I managed to implement the slider but I'm having trouble in displaying the images correctly because of their different sizes.
In the following example, the stackexchange logo is way bigger than the stackoverflow logo. When displaying them with slickR(), the bigger logo makes inroads into the first one like this:
I would also like to have the size of the pictures relative to the size of the screen.
Here is a reproducible example of the Shiny app used to generate the above image:
library(shiny)
library(slickR)
# User interface ----
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
slickROutput("slickr", width = "auto")
)
)
)
# Server ----
server <- function(input, output) {
imgs_links <- list(
"https://upload.wikimedia.org/wikipedia/fr/9/95/Stack_Overflow_website_logo.png",
"https://upload.wikimedia.org/wikipedia/commons/6/6f/Stack_Exchange_Logo.png")
output$slickr <- renderSlickR({
photo_list <- lapply(imgs_links, function(x){
tags$div(
tags$img(src = x, width = "10%", height = "10%")
)
})
imgs <- do.call(tagList, photo_list)
slickR(imgs)
})
}
# Run the application ----
shinyApp(ui = ui, server = server)
What would be the correct way to have each image resized according the size of the screen?
I don't manage to get it with the 'slickR' package. Here is a solution which doesn't use this package, it uses the 'slick' JavaScript library. You have to download the library files and put them in the www/slick-1.8.1/slick folder.
library(shiny)
ui <- fluidPage(
tags$head(
tags$link(rel="stylesheet", type="text/css",
href="slick-1.8.1/slick/slick-theme.css"),
tags$link(rel="stylesheet", type="text/css",
href="slick-1.8.1/slick/slick.css"),
tags$script(type="text/javascript",
src="slick-1.8.1/slick/slick.js"),
tags$script(HTML(
"$(document).ready(function(){
$('#images').slick({
arrows: true,
dots:true
});
});")),
tags$style(HTML(
"#images .slick-prev {
position:absolute;
top:65px;
left:-50px;
}
#images .slick-next {
position:absolute;
top:95px;
left:-50px;
}
.slick-prev:before, .slick-next:before {
color:red !important;
font-size: 30px;
}
.content {
margin: auto;
padding: 2px;
width: 90%;
}"))
),
sidebarLayout(
sidebarPanel(
####
),
mainPanel(
tags$div(
class = "content",
tags$div(
id = "images",
tags$img(
src = "https://upload.wikimedia.org/wikipedia/fr/9/95/Stack_Overflow_website_logo.png",
width = "50vw"
),
tags$img(
src = "https://upload.wikimedia.org/wikipedia/commons/6/6f/Stack_Exchange_Logo.png",
width = "50vw"
)
)
)
)
)
)
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
EDIT: dynamic number of images
library(shiny)
ui <- fluidPage(
tags$head(
tags$link(rel="stylesheet", type="text/css",
href="slick-1.8.1/slick/slick-theme.css"),
tags$link(rel="stylesheet", type="text/css",
href="slick-1.8.1/slick/slick.css"),
tags$script(type="text/javascript",
src="slick-1.8.1/slick/slick.js"),
tags$style(HTML(
"#carousel .slick-prev {
position:absolute;
top:65px;
left:-50px;
}
#carousel .slick-next {
position:absolute;
top:95px;
left:-50px;
}
.slick-prev:before, .slick-next:before {
color:red !important;
font-size: 30px;
}
.content {
margin: auto;
padding: 2px;
width: 90%;
}"))
),
sidebarLayout(
sidebarPanel(
checkboxGroupInput(
"images",
"Select images",
choiceNames = c("Stackoverflow", "Stackexchange", "Asymptote"),
choiceValues = c(
"https://upload.wikimedia.org/wikipedia/fr/9/95/Stack_Overflow_website_logo.png",
"https://upload.wikimedia.org/wikipedia/commons/6/6f/Stack_Exchange_Logo.png",
"https://www.clipartmax.com/png/small/203-2038151_asymptote-vector-graphics-language-wikipedia-rh-en-asymptote.png"
)
)
),
mainPanel(
tags$div(
class = "content",
uiOutput("carousel-ui"),
)
)
)
)
server <- function(input, output) {
output[["carousel-ui"]] <- renderUI({
imgs <- lapply(input[["images"]], function(x){
tags$img(src = x, width = "50vw")
})
imgs_div <- do.call(function(...) div(id = "carousel", ...), imgs)
script <- tags$script(HTML(
"$('#carousel').slick({
arrows: true,
dots:true
});"))
do.call(tagList, list(imgs_div, script))
})
}
# Run the application
shinyApp(ui = ui, server = server)

Make inputs in a sidebar persistent through tabs

I would like to have both a persistent sidebar (as in shinydashboard layout) and a navigation bar with tabs (as in shiny::navbarPage layout). I came across this answer that seems to correspond to what I want.
The problem is that inputs in the sidebar are not persistent through tabs, i.e when switching tabs, the inputs in the sidebar are not displayed anymore (at the contrary of shinydashboard sidebar for example). Here's an example I cannot really minimize more since a lot of it is CSS:
library(shiny)
library(bootstraplib)
# boot dash layout funs ---------------------------------------------------
boot_side_layout <- function(...) {
div(class = "d-flex wrapper", ...)
}
boot_sidebar <- function(...) {
div(
class = "bg-light border-right sidebar-wrapper",
div(class = "list-group list-group-flush", ...)
)
}
boot_main <- function(...) {
div(
class = "page-content-wrapper",
div(class = "container-fluid", ...)
)
}
# css ---------------------------------------------------------------------
css_def <- "
body {
overflow-x: hidden;
}
.container-fluid, .container-sm, .container-md, .container-lg, .container-xl {
padding-left: 0px;
}
.sidebar-wrapper {
min-height: 100vh;
margin-left: -15rem;
padding-left: 15px;
padding-right: 15px;
-webkit-transition: margin .25s ease-out;
-moz-transition: margin .25s ease-out;
-o-transition: margin .25s ease-out;
transition: margin .25s ease-out;
}
.sidebar-wrapper .list-group {
width: 15rem;
}
.page-content-wrapper {
min-width: 100vw;
padding: 20px;
}
.wrapper.toggled .sidebar-wrapper {
margin-left: 0;
}
.sidebar-wrapper, .page-content-wrapper {
padding-top: 20px;
}
.navbar{
margin-bottom: 0px;
}
.navbar-collapse {
font-size: 1.1rem
}
#media (max-width: 768px) {
.sidebar-wrapper {
padding-right: 0px;
padding-left: 0px;
}
}
#media (min-width: 768px) {
.sidebar-wrapper {
margin-left: 0;
position: fixed;
}
.page-content-wrapper {
min-width: 0;
width: 100%;
}
.wrapper.toggled .sidebar-wrapper {
margin-left: -15rem;
}
}
"
# app ---------------------------------------------------------------------
ui <- tagList(
tags$head(tags$style(HTML(css_def))),
bootstrap(),
navbarPage(
collapsible = TRUE,
title = "",
tabPanel(
"Statistics",
boot_side_layout(
boot_sidebar(
selectInput(
"variables",
"Variables",
NULL
)
),
boot_main(
fluidRow(
dataTableOutput("statistics")
)
)
)
),
tabPanel(
"Plots",
boot_side_layout(
boot_sidebar(
),
boot_main(
)
)
)
)
)
server <- function(input, output, session) {
output$statistics <- renderDataTable(mtcars[10, 10])
}
shinyApp(ui, server)
How can I make these inputs persistent through sidebar? (If somebody knows of another simple way to mix persistent sidebar with navbar, please show it as well).
Why not using a sidebarLayout with a navbarPage in mainPanel?
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("select", "Select", c("a", "b", "c"))
),
mainPanel(
navbarPage(
"App Title",
tabPanel("Plot"),
tabPanel("Summary"),
tabPanel("Table")
)
)
)
)
shinyApp(ui, server)
EDIT
Or something like this?
library(shiny)
library(ggplot2)
ui <- fluidPage(
div(
style = "display: flex; flex-direction: column;",
div( #~~ Main panel ~~#
navbarPage(
"Old Faithful Geyser Data",
tabPanel(
"Plot",
plotOutput("ggplot")
),
tabPanel("Summary"),
tabPanel("Table")
)
),
wellPanel( #~~ Sidebar ~~#
style = "width: 300px;",
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
)
)
)
server <- function(input, output) {
output[["ggplot"]] <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
shinyApp(ui = ui, server = server)
EDIT
Like this to have the sidebar on the left:
library(shiny)
library(shinyjs)
library(ggplot2)
CSS <- "
.sidebar {
min-width: 300px;
margin-right: 30px;
}
#sidebar {
width: 300px;
}
"
ui <- fluidPage(
useShinyjs(),
tags$head(tags$style(HTML(CSS))),
div( #~~ Main panel ~~#
navbarPage(
"Old Faithful Geyser Data",
tabPanel(
"Plot",
div(
style = "display: flex;",
div(class = "sidebar"),
plotOutput("ggplot")
)
),
tabPanel(
"Summary",
div(
style = "display: flex;",
div(class = "sidebar"),
verbatimTextOutput("summary")
)
),
tabPanel(
"Table",
div(
style = "display: flex;",
div(class = "sidebar"),
tableOutput("table")
)
),
id = "navbar"
)
),
wellPanel( #~~ Sidebar ~~#
id = "sidebar",
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
)
)
server <- function(input, output) {
output[["ggplot"]] <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output[["summary"]] <- renderPrint({
list(a = 1:10, b = 1:10)
})
output[["table"]] <- renderTable({
iris[1:10,]
})
observeEvent(input[["navbar"]], {
selector <-
sprintf("$('div.tab-pane[data-value=\"%s\"] div.sidebar')", input[["navbar"]])
runjs(paste0(selector, ".append($('#sidebar'));"))
})
}
shinyApp(ui = ui, server = server)
EDIT
Here is an improvement of the above way. I've made some convenient functions tabPanel2 and sidebar to help the user. And I use fluidRow and column instead of using a display: flex;. This allows to have a sidebar width relative to the screen size. The example below also shows how to not include the sidebar in a tab (simply use tabPanel and not tabPanel2.
library(shiny)
library(shinyjs)
library(ggplot2)
tabPanel2 <- function(title, ..., value = title, icon = NULL, sidebarWidth = 4){
tabPanel(
title = title,
fluidRow(
column(
width = sidebarWidth,
class = "sidebar"
),
column(
width = 12 - sidebarWidth,
...
)
)
)
}
sidebar <- function(...){
div(
style = "display: none;",
tags$form(
class = "well",
id = "sidebar",
...
)
)
}
ui <- fluidPage(
useShinyjs(),
div( #~~ Main panel ~~#
navbarPage(
"Old Faithful Geyser Data",
tabPanel2(
"Plot",
plotOutput("ggplot")
),
tabPanel2(
"Summary",
verbatimTextOutput("summary")
),
tabPanel(
"Table",
fluidRow(
column(
width = 4,
wellPanel(
tags$fieldset(
tags$legend(h3("About")),
p("This app is cool")
)
)
),
column(
width = 8,
tableOutput("table")
)
)
),
id = "navbar"
)
),
sidebar( #~~ Sidebar ~~#
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
)
)
server <- function(input, output) {
output[["ggplot"]] <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output[["summary"]] <- renderPrint({
list(a = 1:10, b = 1:10)
})
output[["table"]] <- renderTable({
iris[1:10,]
})
observeEvent(input[["navbar"]], {
selector <-
sprintf("$('div.tab-pane[data-value=\"%s\"] div.sidebar')", input[["navbar"]])
append <- "selector.append($('#sidebar'));"
js <- sprintf("var selector=%s; if(selector.length){%s;}", selector, append)
runjs(js)
})
}
shinyApp(ui = ui, server = server)

Resources