changing body in R shiny when I change menu item - r

I am trying to make the body change as I select different player names.
Here I defined my lists and matrix
nametext <- list(c(“roger” , “rafa” , “marat”))
bodytext <- list(c(“roger text”, “rafa text”, “marat text”))
titletext <- list(c(“The GOAT” , “The Toro”, “My Idol”))
alldata <- data.frame( nametext , bodytext, titletext)
In the next step I set up the dashboard page, including the sidebar menu
ui <- dashboardPage(
dashboardHeader(title = “Best Players in Tennis History”,
titleWidth = 300 #because the title is too long i had to increase the width of the header
),
dashboardSidebar(
width = 300, #to match the width of the header with the sidebar
sidebarMenu(id = “player”,
menuItem(“Roger Federer”, tabName = 1, icon = icon(“user”)),
menuItem(“Rafael Nadal”, tabName = 2, icon = icon(“flash”)),
menuItem(“Marat Safin”, tabName = 3, icon = icon(“fire”))
)
),
I defined the names of the tabs as numbers 1-3. This was done with the objective of dynamically taking the data for the body from the alldata matrix.
So I add this piece of code to the dashboard body:
dashboardBody(
#Roger Federer Tab
box( print( alldata[ input&player , 2]),
title = print( alldata[ input&player ,3]),
solidHeader = TRUE,
width = 12,
height = 300
)
and I keep getting an error saying…
ERROR: object 'input' not found
This is all the code
nametext <- list(c(“roger” , “rafa” , “marat”))
bodytext <- list(c(“roger text”, “rafa text”, “marat text”))
titletext <- list(c(“The GOAT” , “The Toro”, “My Idol”))
alldata <- data.frame( nametext , bodytext, titletext)
ui <- dashboardPage(
dashboardHeader(title = “Best Players in Tennis History”,
titleWidth = 300 #because the title is too long i had to increase the width of the header
),
dashboardSidebar(
width = 300, #to match the width of the header with the sidebar
sidebarMenu(id = “player”,
menuItem(“Roger Federer”, tabName = 1, icon = icon(“user”)),
menuItem(“Rafael Nadal”, tabName = 2, icon = icon(“flash”)),
menuItem(“Marat Safin”, tabName = 3, icon = icon(“fire”))
)
),
dashboardBody(
#Roger Federer Tab
box( print(alldata[ input&player , 2]),
title = print(alldata[ input&player ,3]),
solidHeader = TRUE,
width = 12,
height = 300
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)

Related

How to bring 4 boxes into one row, with golem shiny app?

I am trying to bring 4 boxes per row, into my shiny app. BioTuring and Scope I want aligned on the same row as FLAT and GTEx. This is how it looks now:
One remark, this app is done with golem structure. Thus, please bear in mind when helping and go with the structure I have.
Having said that I have thumbnail_label
thumbnail_label <- function(url, image, label="", content="", tool="misc",
category = "tool") {
tags$a(
href = url,
onclick = paste0("gtag('event', 'click', { 'event_category': '", category,
"', 'event_label': '", tool, "'});"),
target = "_blank",
div(class = "row",
div(class = "col-sm-14 col-md-12",
div(class = "thumbnail",
img(src = image, alt = "...", height = 200, width = 100,
div(class = "caption", h5(label), p(content))
)
)
)
)
)
}
thumnail_label is brought into a module (as per golem). This is my module for gene expressions. I have the feeling this is where I can correct to bring the 2 boxes aligned into one row, alongside FLAT and GTEx.
mod_gene_expressions_sign_path_ui <- function(id){
ns <- NS(id)
tagList(
shinydashboard::tabItem(
tabName = "gene_app",
fluidRow(
shiny::headerPanel(h2("Gene Analysis")),
br(),
column(
3,
thumbnail_label(
url = "https://rstudio-connect.RStudio_FLAT/",
image = "www/Fluidigm.v2.png",
tool = "Fludigm_Browser",
label = "Fludigm Browser",
content = "Perform Fluidigm data analysis"
)
),
br())))
Then gene module above is going into app_ui (as golem structure) see bellow. However, to bring 4 boxes onto the row should not happen in the bellow code, but above.
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# Your application UI logic
shinyUI(
navbarPage(
windowTitle = "Page",
title = div(img(src = ".png", height = "30px"), "Toolbox"),
theme = shinythemes::shinytheme("cerulean"),
tabPanel("Toolbox", icon = icon("wrench"),
shinydashboard::dashboardPage(
header = shinydashboard::dashboardHeader(title = " ", titleWidth = 300),
shinydashboard::dashboardSidebar(
width = 300 ,
shinydashboard::sidebarMenu(
shinydashboard::menuItem(
"Tools",
tabName = "tools_app",
icon = icon("wrench"),
shinydashboard::menuSubItem(
"Gene /Pathways",
tabName = "gene_app",
icon = icon("chart-line")
),
shinydashboard::menuSubItem(
"Genomic",
tabName = "genomic_app",
icon = icon("universal-access")
),
shinydashboard::dashboardBody(
shinydashboard::tabItems(
shinydashboard::tabItem("tools_app", mod_tools_path_ui("tools_path_ui_1")),
shinydashboard::tabItem("gene_app",mod_gene_expressions_sign_path_ui("gene_expression_sign_path_ui_1")),
shinydashboard::tabItem("genomic_app", mod_genomic_ui("genomic_ui_1")),
tabPanel(
"Tutorials", icon = icon("graduation-cap")),
tabPanel("Worflows", icon = icon("list"))
)))
}
Can someone help me, please?
Keeping golem structure, I have managed to bring the 4 boxes into a row by getting rid of shiny::headerPanel(h2("")),
and this is the final code:
mod_gene_expressions_sign_path_ui <- function(id){
ns <- NS(id)
tagList(
shinydashboard::tabItem(
tabName = "gene_app",
# column(width = 9,
fluidRow(
shiny::headerPanel(h2("Gene Expression Analysis")),
br(),
column(
3,
thumbnail_label(
url = "https://rstudio-connect.scp.astrazeneca.net/RStudio_FLAT/",
image = "www/FluidigmAnalysisToolkit.v2.png",
tool = "Fludigm_Browser",
label = "Fludigm Browser",
content = "Perform Fluidigm data analysis"
)
),
column(
3,
thumbnail_label(
url = "https://gtexportal.org/home",
image = "www/gtex.png",
tool = "GTEx",
label = "GTEx Portal",
content = "Gene expression in normal tissue"
)
),
# shiny::headerPanel(h2("")),
column(
3,
thumbnail_label(
url = "https://azcollaboration.sharepoint.com/:b:/r/sites/BioinformaticsfortheBench/Shared%20Documents/Tools/BioTuring/BioTuring_Installation_Instructions.v2021.5.17.pdf?csf=1&web=1&e=TVpy8S",
image = "www/bioturing.svg",
content = "Platform for single-cell analysis and spatial transcriptomics exploration",
label = "BioTuring",
tool = "BioTuring"
)
),
column(
3,
thumbnail_label(
url = "http://informatics.medimmune.com/shiny/scope/",
image = "www/scope.svg",
content = "Explore available single cell RNA-Seq studies",
label = "SCOPE",
tool = "SCOPE"
)
),
br(),
shiny::headerPanel(h2("Pathway Analysis")),
br(),
column(
3,
thumbnail_label(
url = "https://clarivate.com/cortellis/learning/clarivate-for-astrazeneca1796/",
image = "www/clarivate.png",
tool = "clarivate",
label = "Clarivate",
content = "Pathway analysis tools from Cortellis including MetaCore"
)
),
column(
3,
thumbnail_label(
url = "https://analysis.ingenuity.com/pa/launch.jsp",
image = "www/ipa.png",
tool = "IPA",
label = "Ingenuity Pathway Analysis",
content = "Analyze data using manually curated gene sets"
)
),
column(
3,
thumbnail_label(
url = "https://astrazeneca.onramp.bio",
image = "www/onramp.png",
tool = "OnRamp",
label = "OnRamp - Rosalind",
content = "Interactively explore RNA-seq and ChIP-Seq data"
)
),
br(),
column(
3,
thumbnail_label(
url = "http://software.broadinstitute.org/gsea/msigdb/index.jsp",
image = "www/gsea.png",
tool = "GSEA",
label = "GSEA",
content = "Gene set enrichment analysis"
)
)
)
)
)
}

Filtering data in shinydashboard

I'm having issues with a filter option in my R shinydashboard app. I'm able to filter a dataframe column (padj < 1) but when I incorporate this same filter into the app the data is missing padj rows that are very tiny like 1.41103072458963E-14. I get all rows up to 4 decimal places (0.00011014) but not rows with padj smaller than that. This cuts off dozens of wanted rows.
I may be coding something wrong and have tried searching for similar issues but haven't found any.
The select input I chose is:
pickerInput("FDR", "False Discovery Rate", choices = c(1, 0.1, 0.05, 0.01))
when I try to filter using above input:
genes1 <- reactive({
genes <- DEG2 %>% dplyr::filter(padj <= input$FDR) %>% dplyr::filter(log2FoldChange >= input$FC | log2FoldChange <= -input$FC)
})
Any help/advice is greatly appreciated.
data to be loaded here:
datafile.
See below for the app code.
library(shinydashboard)
library(dashboardthemes)
library(shiny)
library(shinythemes)
library(shinyWidgets)
library(shinycssloaders)
library(shinyjs)
library(htmlTable)
library(DT)
library(dplyr)
library(ggpubr)
library(ggplot2)
library(htmlwidgets)
library(plotly)
library(table1)
# load dataset
DEG2 <- read.csv("DEG2.csv")
# to add color to the spinner
options(spinner.color="#287894")
#############################################
### HEADER #################################
#############################################
header <- dashboardHeader(title = tagList(
tags$span(class = "logo-mini", "Cell"),
tags$span( class = "logo-lg", "My 1st App" )),
titleWidth = 300)
#############################################
### SIDEBAR #################################
#############################################
sidebar <- dashboardSidebar(width = 300, sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Pipeline", tabName = "pipe", icon = icon("bezier-curve")),
menuItem("Something", tabName = "plot", icon = icon("braille")),
menuItem("Something else", tabName = "pathways", icon = icon("connectdevelop")),
menuItem("Contact", tabName = "contact", icon = icon("address-card"))
)
)
#############################################
### BODY #################################
#############################################
body <- dashboardBody(
useShinyjs(), # Set up shinyjs
# changing theme
shinyDashboardThemes(theme = "blue_gradient"),
tabItems(
######### Tab 1 #########################################
tabItem("pipe",
fluidPage(
h2("Pipeline"),
#### STEP 1 ####
box(width = 12, title = "Step1: Filter for DEGs", collapsible = TRUE, collapsed = FALSE, status = "primary", solidHeader = TRUE,
fluidRow(
column(4, offset = 0,
sliderTextInput("FC", "Fold-Change (absolute value)", choices = seq(from= 0, to= 5, by=0.5), grid = TRUE),
pickerInput("FDR", "False Discovery Rate", choices = c(1, 0.1, 0.05, 0.01)),
setSliderColor(color = '#EE9B00', sliderId = 1),),
column(6, offset= 1,
valueBoxOutput("genes_filtered", width = 4))),
br(),
fluidRow(
column(10, offset =0,
DT::dataTableOutput("genetable") %>% withSpinner(type = 8, size=1))),
br(),
actionBttn("step1", "Select to advance:step 2", color = "warning", style = "fill", icon = icon("angle-double-down" ))
)),
#### STEP 2 ####
conditionalPanel(
condition = "input.step1 == 1",
fluidPage(
box(width = 12, title = "Step2: Filter for gene regulation", collapsible = TRUE, collapsed = FALSE, status = "primary", solidHeader = TRUE,
"Choose to subset the genes that are up or down regulated",
br(),
br(),
fluidRow(
column(6, offset = 0,
prettyRadioButtons("reg", "Choose:", choices = c("Up-regulated", "Down-regulated", "All"), status = "success", fill=TRUE, inline = TRUE))
),
br(),
fluidRow(
column(6, offset = 0,
valueBoxOutput("value", width = 6)))
) # box
)
) # conditional panel
)# end tab3
) # end tabItems
)#dashboardBody
ui <- dashboardPage(header = header,
sidebar = sidebar,
body = body
)
server <- function(input, output, session) {
############################################
###### TAB1 ##################
############################################
# step 1
genes1 <- reactive({
genes <- DEG2 %>% dplyr::filter(padj <= input$FDR) %>% dplyr::filter(log2FoldChange >= input$FC | log2FoldChange <= -input$FC)
})
output$genes_filtered <- renderValueBox({
valueBox(value=length(genes1()$symbol), subtitle = "Filtered genes", color = "purple", icon=icon("filter"))
})
output$genetable <- DT::renderDataTable({
genes1() }, server = FALSE, extensions =c("Responsive", "Buttons"), rownames = FALSE, options = list(dom = 'Blfrtip', buttons = list('copy', list(extend = "collection",
buttons = c("csv", "excel", "pdf"),
text = "Download")))
)
# step 2
genes2 <- reactive({
g2 <- if (input$reg == "Up-regulated"){
genes1() %>% filter(log2FoldChange > 0)
} else if (input$reg == "Down-regulated"){
genes1() %>% filter(log2FoldChange < 0)
} else {
genes1()
}
})
output$value <- renderValueBox({
if (input$reg == "Up-regulated"){
valueBox(value = length(genes2()$symbol), subtitle = "Up-regulated genes", color = "red", icon = icon("hand-point-up"))
} else if (input$reg == "Down-regulated"){
valueBox(value = length(genes2()$symbol), subtitle = "Down-regulated genes", color = "blue", icon = icon("hand-point-down"))
} else {
valueBox(value = length(genes2()$symbol), subtitle = "All genes", color = "orange", icon = icon("record-vinyl"))
}
})
} #server
shinyApp(ui, server)
Try as.numeric(input$FDR) in your filter as shown below.
genes <- DEG2 %>% dplyr::filter(padj <= as.numeric(input$FDR))

How to prevent plot from overspilling out of box in shiny box?

I stumbled upon this wierd interaction between collapsed boxes within boxes and plots:
In the the first instance of this, in the minimal working example below, on the left side, expanding the box pushes the plot over the edge of the box, while in the second instance on the right side, it does not.
Also, uncommenting the code of the action button somehow remedies this somehow.
Can someone explain to me why this is happening and how to solve the issue?
I am aware that I could just use the layout to the right, but I would really like to understand this behavior.
Thanks in advance!
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidPage(
box(width = 12,
title = "Some Title",
collapsible = TRUE,
solidHeader = TRUE,
status = "danger",
box(widht = 12,
title = "Some Sub Title",
collapsible = TRUE,
solidHeader = TRUE,
box(
width = 12,
title = "Details 1",
collapsible = TRUE,
solidHeader = TRUE,
collapsed = TRUE,
status = "info",
tableOutput("Placeholder_Table_1")
),
#actionButton(inputId = "Action_1",
# label = "Does nothing"
#),
plotOutput("Placeholder_Plot_1")
),
box(widht = 12,
title = "Sub Title 2",
collapsible = TRUE,
solidHeader = TRUE,
plotOutput("Placeholder_Plot_2"),
box(
width = 12,
title = "Details 2",
collapsible = TRUE,
solidHeader = TRUE,
collapsed = TRUE,
status = "info",
tableOutput("Placeholder_Table_2")
)
)
)
)
)
)
server <- function(input, output) {
output$Placeholder_Table_1 <- renderTable(
tibble('Variable 1' = "X",
'Variable 2' = "Y",
'Variable 3' = "Z"
)
)
output$Placeholder_Table_2 <- renderTable(
tibble('Variable 1' = "X",
'Variable 2' = "Y",
'Variable 3' = "Z"
)
)
output$Placeholder_Plot_1 <- renderPlot(
ggplot(data = mtcars) +
labs(title = "Placeholder Plot 1")
)
output$Placeholder_Plot_2 <- renderPlot(
ggplot(data = mtcars) +
labs(title = "Placeholder Plot 2")
)
}
shinyApp(ui, server)
The problem is not the plot, it comes from the box.
First thing you need to know is box is actually using .col-xxx classes from bootstrap and these classes have a CSS float: left;. It will cause itself has 0 height of the parent div. Read this: CSS: Floating divs have 0 height.
However, what you see is it takes some spaces on the UI, so what you see the height is box + plot, but in the parent div height calculation, it's just the plot.
To fix, very easy, wrap your box with fluidrow, .row has a CSS display: table which solves the problem.
fluidRow(box(
width = 12,
title = "Details 1",
collapsible = TRUE,
solidHeader = TRUE,
collapsed = TRUE,
status = "info",
tableOutput("Placeholder_Table_1")
)),

Issue in inserting value with rhandsontable

Thanks for taking your valuable time to pitch in into this question. :-)
I'm building a shiny app that would take user inputs through rhandsontable and save it as a .rds file for data persistence.
The code is as follows:
Global.r
library(shiny)
library(shinydashboard)
library(shinycssloaders
library(rhandsontable)
library(htmltools)
library(plotly)
library(shinyjs)
library(tidyverse)
library(DT)
# Reads the data stored already
raw_data_projects <- readRDS("Projects.rds")
# code to refresh app so as to display the newly added data
jsResetCode <- "shinyjs.reset = function() {history.go(0)}"
ui.R
dashboardPage(skin = "black",
dashboardHeader(dropdownMenuOutput("dropdownmenu"),title = "PMO Dashboard",
tags$li(div(img(src = 'TechM_logo.png',
height = "35px"),
style = "padding-top:10px; padding-bottom:10px;"),
class = "dropdown"),dropdownMenuOutput("msgOutput")) ,
dashboardSidebar(
sidebarMenu(
menuItem("Home", tabName = "home", icon = icon("home")),
menuItem("Projects", tabName = "pros", icon = icon("briefcase")),
menuItem("About Team", tabName = "teamstr", icon = icon("user-friends")),
menuItem("Training & Skills",tabName = "skills",icon = icon("book"))
)),
dashboardBody(
useShinyjs(), # Include shinyjs in the UI
extendShinyjs(text = jsResetCode),
tags$link(rel = "stylesheet", type = "text/css", href = "style_2.css"),
tabItems(
tabItem(tabName = "pros",
fluidPage(tabBox(width = "500px",
tabPanel("Metrics",
fluidRow(
valueBoxOutput("Completed", width = 3),
valueBoxOutput("WIP", width = 3),
valueBoxOutput("Delayed", width = 3),
valueBoxOutput("OnHold", width = 3)
),
fluidRow(
box(plotlyOutput("Project_category"), width = 4,solidHeader = TRUE, status = "primary", title = "Project Category", collapsible = TRUE),
box(plotlyOutput("Project_status"), width = 8,solidHeader = TRUE, status = "primary", title = "Project Status", collapsible = TRUE),
box(plotlyOutput("Complexity"), width = 4,solidHeader = TRUE, status = "primary", title = "Project Complexity", collapsible = TRUE),
box(plotlyOutput("Audits"), width = 4,solidHeader = TRUE, status = "primary", title = "Audit Status", collapsible = TRUE)
)),
tabPanel("Data",
box(withSpinner(rHandsontableOutput("Projects")), width = 12),
actionButton("saveBtnProjects", "Save Projects", icon = icon("save")),
actionButton("BtnResetProjects", "Reset Filters", icon = icon("eraser")))))
)))
server.r
shinyServer(function(input, output, session){
dt_projects <- reactive({ raw_data_projects })
vals <- reactiveValues()
output$Projects <- renderRHandsontable({
rhandsontable(dt_projects(), readOnly = FALSE, search = TRUE, selectCallback = TRUE ) %>%
hot_cols(columnSorting = TRUE, manualColumnMove = TRUE, manualColumnResize = TRUE ) %>%
hot_table(highlightRow = TRUE, highlightCol = TRUE) %>%
#hot_col("PROJECT.STATUS", renderer = text_renderer, type = "autocomplete") %>%
hot_rows(fixedRowsTop = 1)
})
# on click of button the file will be saved to the working directory
observeEvent(input$saveBtnProjects,
#write.csv(hot_to_r(input$Projects), file = "./Data/project_tracker.csv",row.names = FALSE)
saveRDS(hot_to_r(input$Projects),"Projects.rds")
)
# refresh the page
observeEvent(input$saveBtnProjects, {js$reset()})
})
So when I run the app I get the table I desire as below:
As we can see, as I was inserting values to the first column, all the other columns greyed out and I couldn't insert any values into it. Please help me with this issue.
Also please suggest if my code will display the data reactively as soon as I save the data by pressing Save Projects button.
Thanks a ton in advance!!
P.S : I have included the server code only for the table considering the length of the question leaving the code of other tabs. But still this code is reproducible.

how to get the list in R shinydashboard

I am getting the all the text like a paragraph. I want all the text in the list format for example - li in html. Please help me in this. I tried using vector but was not able to do. That is the reason i appended each and every text using paste0 method using sep="\n" But \n is not showing up with new line.
My ui.R file is
# shinydashboard makes it easy to use Shiny to create dashboards
# shinydashboard requires Shiny 0.11 or above
#First Selecting the shiny Dashboard
library(shiny)
library(shinydashboard)
library(openxlsx)
FileNames <- list.files("ExcelSheets/")
countDays <- length(FileNames)
positive = 0
neutral = 0
negative = 0
count = 0
positiveTweets = ""
negativeTweets = ""
neutralTweets = ""
p = 1
nu = 1
ng = 1
for (i in seq(1, length(FileNames)))
{
excelSheetData = read.xlsx(paste0("ExcelSheets/", FileNames[i]), startRow = 0, colNames = TRUE, detectDates = TRUE)
countRows <- dim(excelSheetData)
countRows <- countRows[1]
rows <- countRows
count = count + rows
data = excelSheetData[, c("polarity", "polarity_confidence", "Text")]
for (j in seq(1, rows)){
if(data[j, 1] == "positive")
{
positive = positive + data[j, 2]
positiveTweets = paste0(positiveTweets, paste0(paste(paste0(p, ":"), data[j,3]), "\n"))
p = p + 1
}
else if(data[j, 1] == "negative")
{
negative = negative + data[j, 2]
negativeTweets = paste0(negativeTweets, paste0(paste(paste0(ng, ":"), data[j,3]), "\n"))
ng = ng + 1
}
else
{
neutral = neutral + data[j, 2]
neutralTweets = paste0(neutralTweets, paste0(paste(paste0(nu, ":"), data[j,3]), "\n"))
nu = nu + 1
}
}
}
total <- positive + negative + neutral
positivePercent <- round((positive * 100) / total)
negativePercent <- round((negative * 100) / total)
neutralPercent <- round((neutral * 100) / total)
countVect = c(positive, neutral, negative)
shinyUI(dashboardPage(
dashboardHeader(title = "Sentiment Analysis"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Tweets", icon = icon("twitter"),
menuSubItem("Positive Tweets", tabName = "pTweets", icon = icon("thumbs-up")),
menuSubItem("Neutral Tweets", tabName = "neuTweets", icon = icon("hand-spock-o")),
menuSubItem("Negative Tweets", tabName = "negTweets", icon = icon("thumbs-down"))
)
)
),
## Body content
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
div(class = "my-class", h2("Sentiment Analysis of Twitter Tweets using RapidMinor and Shiny Dashboard.")),
fluidRow(
valueBox(count, "Total Number of Tweets Analyzed in the competition", icon = icon("twitter"), width = 6),
valueBox(countDays, "Number of Days ", icon = icon("calendar-check-o"), width = 6, color = "yellow")
),
fluidRow(
infoBox("Positive", paste(positivePercent, "%"), icon = icon("thumbs-up"), width = 4, fill = TRUE, color = "green"),
infoBox("Neutral", paste(neutralPercent, "%"), icon = icon("hand-spock-o"), width = 4, fill = TRUE, color = "light-blue"),
infoBox("Negative", paste(negativePercent, "%"), icon = icon("thumbs-down"), width = 4, fill = TRUE, color = "red")
)
),
# Positive Tweets tab content
tabItem(tabName = "pTweets",
h2("Positive Tweets #Brexit"),
h4(positiveTweets)
),
# Neutral Tweets tab content
tabItem(tabName = "neuTweets",
h2("Neutral Tweets #Brexit"),
h4(neutralTweets)
),
# Negative Tweets tab content
tabItem(tabName = "negTweets",
h2("Negative Tweets #Brexit"),
h4(negativeTweets)
)
)
)
))
My server.R file is
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(shinydashboard)
shinyServer(function(input, output) {
})
A possible solution to your problem would be to append vectors with html tag <br>instead of "\n" (which would work fine with cat and verbatimTextOutput) and then to wrap, say, positiveTweets into HTML function like this:
h4(HTML(positiveTwe‌​ets))
You also want to display new tabs with the names of files in the current working directory.
In the example below I created a new menuItem which contains a random number of tabs which have random names.
First, in dashboardHeader I added dynamical output with an ID out1.
menuItemOutput("out1")
After that, on the server side, for testing purposes, I defined a variable my_files which contains a random number of tabs with random names. It will be updated each time you run the app.
Finally, within renderUI I defined menuItem ("Files") and placed within it a dynamical number of menuSubItems, which are generated with lapply.
output$out1 <- renderUI({ ... })
I also added a comment which tries to explain what you could do if you wanted to update a list of files in a working directory (and hence the names of tabs in the app) while the app is running.
Full example:
library(shiny)
library(shinydashboard)
#library(openxlsx)
rm(ui)
rm(server)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "Sentiment Analysis"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Tweets", icon = icon("twitter"),
menuSubItem("Positive Tweets", tabName = "pTweets", icon = icon("thumbs-up")),
menuSubItem("Neutral Tweets", tabName = "neuTweets", icon = icon("hand-spock-o")),
menuSubItem("Negative Tweets", tabName = "negTweets", icon = icon("thumbs-down"))
),
menuItemOutput("out1") # added
)
),
## Body content
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
div(class = "my-class", h2("Sentiment Analysis of Twitter Tweets using RapidMinor and Shiny Dashboard.")),
fluidRow(
#valueBox(count, "Total Number of Tweets Analyzed in the competition", icon = icon("twitter"), width = 6),
valueBox(15, "Total Number of Tweets Analyzed in the competition", icon = icon("twitter"), width = 6),
#valueBox(countDays, "Number of Days ", icon = icon("calendar-check-o"), width = 6, color = "yellow")
valueBox(10, "Number of Days ", icon = icon("calendar-check-o"), width = 6, color = "yellow")
),
fluidRow(
#infoBox("Positive", paste(positivePercent, "%"), icon = icon("thumbs-up"), width = 4, fill = TRUE, color = "green"),
infoBox("Positive", "80%", icon = icon("thumbs-up"), width = 4, fill = TRUE, color = "green"),
infoBox("Neutral", "15%", icon = icon("hand-spock-o"), width = 4, fill = TRUE, color = "light-blue"),
infoBox("Negative", "5%", icon = icon("thumbs-down"), width = 4, fill = TRUE, color = "red")
)
),
# Positive Tweets tab content
tabItem(tabName = "pTweets",
h2("Positive Tweets #Brexit"),
#h4(positiveTweets)
h4("Great")
),
# Neutral Tweets tab content
tabItem(tabName = "neuTweets",
h2("Neutral Tweets #Brexit"),
#h4(neutralTweets)
h4("ok")
),
# Negative Tweets tab content
tabItem(tabName = "negTweets",
h2("Negative Tweets #Brexit"),
#h4(negativeTweets)
h4("shit :D")
)
)
)
))
server <- function(input, output) {
#my_files will be updated each time you run the app
#my_files <- list.files()
# for testing purposes generate 5 tabs with names given by random letters
my_files <- letters[sample(1:26, 5)]
# There could also be the case when there is no files in a folder
# You can handle it with `req` or `validate(need(...))` functions
#my_files <- ""
output$out1 <- renderUI({
# Just in case if you would put new files to the folder
# while the app is working and wanted an update of tabs:
# - create eventReactive with an actionButton which will
# return list.files().
# - pass new names of files to this renderUi function.
# be careful because "tabName" must not have a "." in it.
req(my_files) # show tabs only if there are files in a directory
# generate and save tabs in a list
tabs <- lapply(seq_along(my_files), function(i) {
menuSubItem(my_files[i], tabName = my_files[i], icon = icon("thumbs-up"))
})
menuItem("Files", tabName = "Files", icon = NULL, tabs)
})
}
shinyApp(ui, server)

Resources