Skip decimal numbers from values with "thousands" mark in a DT::datatable() - r

In the DT::datatable() of my shiny app below I have found how to add "thousands" mark )(.) in my table but I want to get rid of the decimals numbers.
library(shiny)
library(shinydashboard)
library(DT)
## app.R ##
library(shiny)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
),
dashboardBody(
dataTableOutput("table")
)
)
server <- function(input, output) {
iris<-iris[,1:4]*100000
output$table <- renderDataTable({
datatable(iris) %>%
formatCurrency(columns = c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"), currency = "", interval = 3, mark = ".") %>%
formatStyle(
columns = c("Sepal.Length")
) })
}
shinyApp(ui, server)

Just add digits=0 to the formatCurrency().

Related

Modify column names in rhandsontable

Is it possible to change the column names manually in rhandsontable? Also why cant I add a new row or column here?
## app.R ##
library(shiny)
library(shinydashboard)
library(rhandsontable)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
),
dashboardBody(
rHandsontableOutput('table')
)
)
server <- function(session,input, output) {
output$table <- renderRHandsontable({
rhandsontable(iris, width = 550, height = 300) %>%
hot_context_menu(allowRowEdit = FALSE, allowColEdit = FALSE)
})
}
shinyApp(ui, server)

Empty the search bar of a datatable by default instead of including the highlighted text

Is there a way to make the Search bar of the datatable empty instead of having the 'setosa' inside it by default while keeping the 'setosa' highlighted inside the table? Or at least find another way to highlight or underline the 'setosa'?
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic sidebar"),
dashboardSidebar(
),
dashboardBody(
DT::dataTableOutput("t")
)
)
server <- function(input, output) {
output$t <- renderDT(
datatable(iris, options = list(searchHighlight = TRUE, search = list(search = 'setosa')))
)
}
shinyApp(ui, server)
Ok, you can do something like this.
library(DT)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic sidebar"),
dashboardSidebar(
),
dashboardBody(
DT::dataTableOutput("t")
)
)
server <- function(input, output) {
data <- reactive({
mydata <- iris
rownames(mydata) <- gsub("setosa",tags$span(style="color:red", "setosa"),rownames(mydata))
for(i in 1:ncol(mydata)){
mydata[,i] <- gsub("setosa",tags$span(style="color:red", "setosa"),mydata[,i])
}
mydata
})
output$t <- renderDT(
datatable(data(), options = list(searchHighlight = TRUE, search = list(search = '')), escape = F)
)
}
shinyApp(ui, server)

How to display a dynamic number of outputs in R shiny?

What I do:
I have a shiny App that returns every column of my csv as a verbatim ouput. I attached my current code (UI.R and Server.R) and the csv-File below.
My Question: I need to write such an app for many different csv-files that all have a variing number of columns. How do I do this automatically without having to write
output$myColumn01 = renderPrint({
as.character(D$Names)
})
and
h1("Names"),
verbatimTextOutput("myColumn01"),
for every column manually?
-
Here is my csv ("myCSV.csv"):
Names;Pages;Scores;Numbers
George;T;3;5
Jim;I;4;23
Jack;T;6;12
Anna;R;4;3
Here is my server.R-File:
library(shiny)
library(dplyr)
library(shinydashboard)
server <- shinyServer(function(input, output, session) {
D = read.csv(file = "myCSV.csv", sep = ";")
output$myColumn01 = renderPrint({
as.character(D$Names)
})
output$myColumn02 = renderPrint({
as.character(D$Pages)
})
output$myColumn03 = renderPrint({
as.character(D$Scores)
})
output$myColumn04 = renderPrint({
as.character(D$Numbers)
})
})
Here is my ui.R-File:
library(shiny)
library(dplyr)
library(shinydashboard)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "Sessions"),
dashboardSidebar(
width = 350,
collapsed = TRUE,
""
),
dashboardBody(
h1("Names"),
verbatimTextOutput("myColumn01"),
h1("Pages"),
verbatimTextOutput("myColumn02"),
h1("Scores"),
verbatimTextOutput("myColumn03"),
h1("Numbers"),
verbatimTextOutput("myColumn04")
)
))
Is it what you expect ?
library(shiny)
library(dplyr)
library(shinydashboard)
server <- shinyServer(function(input, output, session) {
D = read.csv(file = "myCSV.csv", sep = ";")
lapply(1:ncol(D), function(i){
output[[sprintf("myColumn%02d",i)]] <-
renderPrint({
as.character(D[[colnames(D)[i]]])
})
})
output$ui <- renderUI({
lapply(1:ncol(D), function(i){
tagList(
h1(colnames(D)[i]),
verbatimTextOutput(sprintf("myColumn%02d",i))
)
})
})
})
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "Sessions"),
dashboardSidebar(
width = 350,
collapsed = TRUE,
""
),
dashboardBody(
uiOutput("ui")
)
))
shinyApp(ui=ui, server=server)

Implementing span to click on plot and move in R shiny

The given code creates a simple scatterPlot. I wish to click on the plot and move it in any direction that I want to, basically the span functionality. Attached the snapshot for references.Please help and thanks.
## app.R ##
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(lubridate)
library(dplyr)
library(knitr)
library(XML)
library(xml2)
library(data.table)
library(ggplot2)
library(ggthemes)
library(glue)
library(tibble)
library(miniUI)
library(tidyr)
library(shinyTime)
library(petrinetR)
library(magrittr)
library(shinyWidgets)
library(DiagrammeR)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
grVizOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderDiagrammeR(
{
patients %>% process_map()
}
)
}
shinyApp(ui, server)
You can use plotly
## app.R ##
library(shiny)
library(plotly)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
plotlyOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderPlotly(
{
plot_ly(iris, x= iris$Petal.Length, y = iris$Sepal.Length)
}
)
}
shinyApp(ui, server)

Formatting being lost on a shiny app when using column

I have a shiny dashboard where i am using a tab Panel and in that panel I'm trying to place two summary tables side by side
The tables seem to lose the background of the tabPanel
Does anyone know why
Reproducible example below
library(shiny)
library(shinydashboard)
library(dplyr)
data(iris)
server <- function(input, output) {
output$top_Length = renderTable({
mydf <- iris %>%
arrange(desc(Sepal.Length)) %>%
slice(1:10)
mydf
})
output$top_width = renderTable({
mydf <- iris %>%
arrange(desc(Sepal.Width)) %>%
slice(1:10)
})
}
header <- dashboardHeader(title = "Flower Power")
sidebar <- dashboardSidebar(disable = TRUE)
body <- dashboardBody(fluidRow(
tabBox(title = "Charting Information",width = 9,
tabPanel("Trending"),
tabPanel("Details",
column(4,
h2('Top Sepal Length'),
tableOutput('top_Length')
),
column(3,
h2('Top Sepal Width'),
tableOutput('top_width')
)
)
)
))
ui <- dashboardPage(
skin = "yellow",
header,
sidebar,
body
)
shinyApp(ui = ui, server = server)
Use fluidRow to prevent overlapping as below:
fluidRow( column(4,
h2('Top Sepal Length'),
tableOutput('top_Length',width="200")
),
column(3,
h2('Top Sepal Width'),
tableOutput('top_width') )
)

Resources