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)
Related
How can we hide the sorting arrows that are next to the column names in DT::datatable()?
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
datatableOutput("table"))
)
server <- function(input, output) { }
output$table<-renderDataTable({
datatable("iris")
})
shinyApp(ui, server)
options = list(ordering = FALSE)
in the datatable function.
This turns off the sorting for all columns.
If you want to disable for some columns only, say column 2:
options = list(
columnDefs = list(
list(targets = 2, orderable = FALSE)
)
)
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().
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)
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)
I'm using R shiny Dashboard for data visualization in my case i wanted to insert user input into filtering data frame in r
library(shiny)
library(shinydashboard)
ui <-
dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
)
),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "",
sliderInput("slider", "Number of Breaks:", 1, 180, 50)
),
box(
selectInput('BILLING_CENTRE', 'Select Billing Center', names(dfList))
)
)
)
)
server <-
function(input, output) {
d <- read.csv('Events_for_Jan_suspensions.csv')
dfList <- split(d, d$BILLING_CENTRE)
abc <- reactive({input$BILLING_CENTRE})
if (abc == "AD"){
histdata <- dfList$AD$SU_TO_OK_DURATION
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
}
shinyApp(ui, server)