Reduce space between widgets - shiny

Is there a way to reduce the empty space further between widgets as shown below. Reducing space between Date and DF
if (interactive()) {
library(shiny)
library(shinyWidgets)
library(DT)
ui <- fluidPage(
tags$h3("Material switch examples"),
fluidRow(column(width = 7),
fluidRow(box(width = 2, dateInput("date","Date", value = Sys.time(), min = Sys.time(), max = Sys.time()-30)),
box(width = 2, selectInput("df","DF",choices = unique(iris$Species))),
box(width = 2, actionButton("ab","Action")))),
dataTableOutput("df")
)
server <- function(input, output) {
output$df <- DT::renderDataTable({
datatable(head(iris),caption = "Iris",options = list(dom = 'ft'))
})
}
shinyApp(ui, server)
}

You could do this by setting the CSS of the two col-sm-2 class to remove (or decrease) the padding-left and padding-right attributes. The problem is that you may want to add back in the left padding on the date box and the right padding on the df box. You could do that this way:
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
ui <- fluidPage(
tags$h3("Material switch examples"),
tags$style("
.col-sm-2{
padding-right: 0;
padding-left: 0;
}
#date{
padding-left: 25px;
}
#df{
padding-right: 15px;
}
"),
fluidRow(column(width = 7),
fluidRow(box(width = 2, dateInput("date","Date", value = Sys.time(), min = Sys.time(), max = Sys.time()-30)),
box(width = 2, selectInput("df","DF",choices = unique(iris$Species))),
box(width = 2, actionButton("ab","Action")))),
dataTableOutput("df")
)
server <- function(input, output) {
output$df <- DT::renderDataTable({
datatable(head(iris),caption = "Iris",options = list(dom = 'ft'))
})
}
shinyApp(ui, server)

Related

Shiny plot is outside the dashboardBody

Please see attached image. Do you have suggestions how to avoid that the plot is outside the white area, or to make the grey area below the plot white?
ui <- dashboardPage(
# Application title
dashboardHeader(title=h4(HTML("Virus Coverage plot"))),
dashboardSidebar(
useShinyjs(),
selectInput("Taxa", "Taxa", choices = unique(files.Vir.DNA.df.test$V1))
),
dashboardBody(
tabsetPanel(
tabPanel("Taxa", plotOutput("myplot1"))
)
)
)
server <- function(input, output, session) {
data_selected <- reactive({
filter(files.Vir.DNA.df.test, V1 %in% input$Taxa)
})
output$myplot1 <- renderPlot({
#data_selected() %>%
# filter(Cancer=="Anus" | Cancer=="Cervix") %>%
p <- ggplot(data_selected(),aes(position,rowSums, fill = V1)) +
#theme_bw(base_size = 6) +
geom_bar(stat="identity") +
facet_grid(Cancer~. , scales = "free_x", space = "free_x", switch = "x") +
theme(strip.text.y = element_text(angle = 0),
strip.text.x = element_text(angle = 90),
strip.background = element_rect(colour = "transparent", fill = "transparent"),
plot.background = element_rect(colour = "white", fill = "white"),
panel.background = element_rect(colour = "white", fill = "white"),
axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(y="Sum coverage within cancer type", x="", title="") +
scale_fill_manual(values=mycolors) +
theme(legend.position = "none")
#scale_y_log10()
print(p)
},res = 100,width = 600, height = 1200)
}
shinyApp(ui, server)
Your example isn't reproducible - so I made a new one.
You just need to wrap the plotOutput in a fluidRow:
library(shiny)
library(ggplot2)
library(datasets)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
# dashboardBody(plotOutput("myplot")) # exceeds body
dashboardBody(fluidRow(plotOutput("myplot"))) # works
)
server <- function(input, output, session) {
output$myplot <- renderPlot({
scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width))
scatter + geom_point(aes(color=Species, shape=Species)) +
xlab("Sepal Length") + ylab("Sepal Width") +
ggtitle("Sepal Length-Width")
}, height = 1200)
}
shinyApp(ui, server)

Deploying R Shiny did not succeed

I tried to publish an R Shiny app but I got this error 1
I don't know what to do
ps: I have updated all the libraries that I use inside the code but still nothing I get the same error
would you please help me!
I am using the following code:
library(shiny)
library(dplyr)
library(rgdal)
library(leaflet)
library(shinyWidgets)
library(shinydashboard)
basin <- readOGR("data/basin.kml", "basin")
map_allocator1 <- read.csv('data/map_allocator1.csv')
map_allocator2 <- read.csv('data/map_allocator2.csv')
map_allocator3 <- read.csv('data/map_allocator3.csv')
tour_polyline <- readOGR("data/tour1.kml", "tour1")
info_360<- read.csv('data/360_photos.csv')
ui <-
fluidPage(theme = "mystyle.css",
sidebarLayout(
sidebarPanel(
tags$head(
tags$style(HTML(".main-sidebar {background-color: #D6E3F0!important;}")))
,
sliderTextInput(
inputId = "mySliderText",
label = "Story line",
grid = TRUE,
force_edges = TRUE,
choices = c('1','2','3','4','5','6')
)
,br(),br()
,
(leafletOutput("story_map")),
htmlOutput("frame2")
),
mainPanel(
tags$head(tags$style("#current_info{
margin-left:20px;
margin-right:10px;
}"
)
)
,
valueBoxOutput("story_line_valubox"),
htmlOutput("frame")
,
div(id='box1', "Infromation about the current location")
,
htmlOutput("frame1")
#uiOutput("current_info")
)
)
)
server <- function(input, output) {
printmap <- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText)
}
})
printingvaluebox <- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText) %>%
pull(valuebox)
}
})
output$story_map<- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.Watercolor",options = providerTileOptions(minZoom=6, maxZoom=6)) %>%
addPolygons(data = basin,color = "black",weight = 2,opacity = 1,fillOpacity = 0.05 )%>%
addCircleMarkers(data = map_allocator1,
lat = ~lat, lng = ~lon,
label = ~no,
radius = 8, fillOpacity = 3/4, stroke = FALSE, color = 'steelblue',
labelOptions = labelOptions(noHide = TRUE, offset=c(0,0), textOnly = TRUE)
)%>%
addCircleMarkers(data = map_allocator2,
lat = ~lat, lng = ~lon,
label = ~no,
radius = 8, fillOpacity = 3/4, stroke = FALSE, color = 'red',
labelOptions = labelOptions(noHide = TRUE, offset=c(0,0), textOnly = TRUE)
)%>%
addCircleMarkers(data = map_allocator3,
lat = ~lat, lng = ~lon,
label = ~no,
radius = 8, fillOpacity = 3/4, stroke = FALSE, color = 'yellow',
labelOptions = labelOptions(noHide = TRUE, offset=c(0,0), textOnly = TRUE)
)%>%
addPolylines(data=tour_polyline, color = "red",weight = 1,opacity = 1)%>%
addMarkers(data=printmap())
})
output$story_line_valubox <- renderValueBox({
valueBox(
printingvaluebox(),
width = 7,
"Current Excursion Station",
color = "blue"
)
})
output$story_line_map<- renderLeaflet({
leaflet() %>%
addProviderTiles("Esri.WorldImagery",options = tileOptions(minZoom = 3 , maxZoom = 16)) %>%
setView(lng=printmap()$lon, lat=printmap()$lat, zoom=printmap()$zoom_level)
})
selectHtml <- reactive({
if (input$mySliderText ==1)
{
return(("trial1.html"))
}
else
{
return(("triaL2.html"))
}
})
frame_link<- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText) %>%
pull(mapox)
}
})
output$frame <- renderUI({
tags$iframe(src=frame_link(), height=700, width=1000)
})
output$frame1 <- renderUI({
tags$iframe(src=selectHtml(), height=700, width=1000)
})
output$frame2 <- renderUI({
tags$iframe(src='carousel.html', height=390, width=575, style="position:relative; top: 20px; left: 0px;")
})
}
# Run the application
shinyApp(ui = ui, server = server)
I have published 3 apps in R Shiny and all of them were successfully completed, this time I don't know what is the exact problem!

Small icon in DT table

Can we add a small icon next to values in DT table. Example
if (interactive()) {
library(shiny)
library(shinyWidgets)
library(DT)
ui <- fluidPage(
tags$h3("Material switch examples"),
fluidRow(column(width = 12),
fluidRow(box(width = 4, dateInput("date","Date", value = Sys.time(), min = Sys.time(), max = Sys.time()-30)),
box(width = 7, selectInput("df","DF",choices = unique(iris$Species)),offset = 0),
box(width = 2, actionButton("ab","Action")))),
dataTableOutput("df")
)
server <- function(input, output) {
output$df <- DT::renderDataTable({
datatable(head(iris),caption = "Iris",options = list(dom = 'ft'))
})
}
shinyApp(ui, server)
}
IN the above DT table, can we add upward arrow next to Setosa . (It should be clickable)
Expect Output
You could use icon to display an up arrow.
library(shiny)
library(shinyWidgets)
library(DT)
library(dplyr)
ui <- fluidPage(
tags$h3("Material switch examples"),
dataTableOutput("df")
)
server <- function(input, output) {
data <- head(iris) %>% mutate(Species = paste(Species,as.character(icon("arrow-up", lib = "glyphicon"))))
output$df <- DT::renderDataTable({
datatable(data,caption = "Iris",options = list(dom = 'ft'),escape=FALSE, selection = list(mode = 'single',target = 'cell'))
})
}
shinyApp(ui, server)

how can i use download button for download highchart in shiny

How can I use a download button instead of hc_exporting function to download a highchart in shiny?
library(shiny)
library(shinydashboard)
library(highcharter)
library(shinyWidgets)
RecruitmentFunneldb_struct <-
structure(list(
yyyy = c(2019L, 2019L, 2019L, 2019L, 2019L, 2019L),
stages = c(
"Phone Scrining",
"Interview",
"Offer",
"Pre-Onboarding",
"Post-Joining",
"Joined"
),
pop = c(8L, 25L, 23L, 32L, 8L, 4L)
),
row.names = c(NA,
6L),
class = "data.frame")
ui <-
dashboardPage(
dashboardHeader(
title = HTML("Analytic view - Recruitment"),
titleWidth = 280
),
dashboardSidebar(disable = T),
dashboardBody(fluidPage(fluidRow(
box(
title = fluidRow(
column(10, "Recruitment Funnel"),
column(
2,
align = "right",
downloadButton("download", label = NULL, class = "butt1"),
tags$head(
tags$style(
".butt1{display: inline-block;} .butt1{font-size: 20px;} .butt1{border: none;} .butt1{padding-top: 1px} .butt1{background-color: transperent .butt1{padding-right: 50px}}"
)
)
)
),
solidHeader = T,
width = 4,
collapsible = F,
highchartOutput("Recruitment_Funnel", height = "240px")
)
)))
)
server <- function(input, output, session) {
output$Recruitment_Funnel <- renderHighchart({
Reserve_Data <- RecruitmentFunneldb_struct %>% arrange(-pop)
Reserve_Data %>%
hchart("funnel", hcaes(x = stages, y = pop))
})
output$download <- downloadHandler(
filename = function() {
paste("Funnel", ".", "pdf")
},
content = function(file) {
pdf(file)
output$Recruitment_Funnel()
dev.off()
}
)
}
shinyApp(ui, server)

Get only InputIDs that have changed

Is it possible to select/get only the input names of the widgets that have changed? Say that I have a Shiny App and that I deselect a box of a checkboxGroupInput. Is it possible to somehow get the inputId of that widget?
Here is a solution using basic shiny:
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins1",
"Number of bins 1:",
min = 1,
max = 50,
value = 30),
sliderInput("bins2",
"Number of bins 2:",
min = 1,
max = 50,
value = 30),
textOutput("printChangedInputs")
),
mainPanel(
plotOutput("distPlot1"),
plotOutput("distPlot2")
)
)
)
server <- function(input, output) {
output$distPlot1 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins1 + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$distPlot2 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins2 + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
previousInputStatus <- NULL
changedInputs <- reactive({
currentInputStatus <- unlist(reactiveValuesToList(input))
if(is.null(previousInputStatus)){
previousInputStatus <<- currentInputStatus
changedInputs <- NULL
} else {
changedInputs <- names(previousInputStatus)[previousInputStatus != currentInputStatus]
print(paste("Changed inputs:", changedInputs))
previousInputStatus <<- currentInputStatus
}
return(changedInputs)
})
output$printChangedInputs <- renderText({paste("Changed inputs:", changedInputs())})
}
shinyApp(ui = ui, server = server)
Edit: Another way would be to listen for the JavaScript event shiny:inputchanged:
library(shiny)
ui <- fluidPage(
tags$head(
tags$script(
"$(document).on('shiny:inputchanged', function(event) {
if (event.name != 'changed') {
Shiny.setInputValue('changed', event.name);
}
});"
)
),
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins1",
"Number of bins 1:",
min = 1,
max = 50,
value = 30),
sliderInput("bins2",
"Number of bins 2:",
min = 1,
max = 50,
value = 30),
textOutput("changedInputs")
),
mainPanel(
plotOutput("distPlot1"),
plotOutput("distPlot2")
)
)
)
server <- function(input, output) {
output$distPlot1 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins1 + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$distPlot2 <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins2 + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$changedInputs <- renderText({paste("Changed inputs:", input$changed)})
}
shinyApp(ui = ui, server = server)
Please see this for more information.