I have created the following interface using R shiny.
library(shiny)
ui <- fluidPage(
#Can be fluid row also
fluidRow(
column(3,
h3("Excel DB"),
hr(),
fileInput("file1", "Excel DB",
multiple = TRUE,
accept = c("text/csv/xlsx/xls",
"text/comma-separated-values,text/plain",
".csv", ".xls", ".xlsx")),
textInput(inputId = 'Type',label = 'Type'),
textInput(inputId = 'Client',label = 'Client'),
textInput(inputId = "Task", label = "Task"),
actionButton(inputId = "ClearAll", label = "Clear Screen"),
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Regression",
"Log" = "Logistic Regression"))
),
column(5,h5(' '),
hr(), downloadButton(outputId = "Downloaddata", label = "Fetch Dataset"),
textInput(inputId = "Commodity", label = "Commodity"),
textInput(inputId = "Year", label = "Year"),
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear Regression",
"Log" = "Logistic Regression")),
numericInput(inputId = "Numberinput", label = "Numinput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)
), sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100, step
= 2.5, value = 1)
)
I have created the following empty server
server<-function(input, output){}
shinyApp(ui, server)
The above code creates a shiny application with a sidebar panel having two columns. However, the 2 columns are not aligned with each other. I would like to know how to arrange the components of the app as follows.
The fetch dataset button should be along the browse button. Similarly the commodity text box should be next to type text box and the year box should come near the client. The two sets of radio buttons should align with each other. I request some help here. Am unable to arrange them in that pattern
To achieve this you need to do some nesting of column() and fluidRow(). This answer should explain enough to get you started, along with the examples on Shiny's layout guide. I believe the following should get you roughly what you want:
library(shiny)
ui <- fluidPage(
#Can be fluid row also
h3("Excel DB"),
hr(),
fluidRow(
column(12,
fluidRow(
column(3,
fileInput("file1", NULL,
multiple = TRUE,
accept = c("text/csv/xlsx/xls",
"text/comma-separated-values,text/plain",
".csv", ".xls", ".xlsx"))),
column(5,
column(3,
downloadButton(outputId = "Downloaddata", label = "Fetch Dataset")),
column(2, offset = 2,
actionButton(inputId = "ClearAll", label = "Clear Screen"))
)
),
fluidRow(
column(3,
textInput(inputId = 'Type',label = 'Type'),
textInput(inputId = 'Client',label = 'Client'),
textInput(inputId = "Task", label = "Task")
),
column(5,
textInput(inputId = "Commodity", label = "Commodity"),
textInput(inputId = "Year", label = "Year"),
numericInput(inputId = "Numberinput", label = "Numinput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)),
fluidRow(
column(3,
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Regression",
"Log" = "Logistic Regression"))),
column(5,
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear Regression",
"Log" = "Logistic Regression")))
),
fluidRow(
column(5,
sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100,
step = 2.5, value = 1))
)
)
)
)
Created on 2018-09-20 by the reprex package (v0.2.1)
Related
I am trying to display some input field alongside some output field inputted from another tab. However the output field is going below and cannot align with the rest.
Code given below:-
fluidRow(
column(3, sliderInput(inputId = "avg_planned_miles", label = "Average Planner Miles", min = 5, max = 50, value = 9, step = 0.1)),
column(3, textInput(inputId = "batch_pct", label = "Batch %", value = "0.5")),
column(3, h4("Volume: "), verbatimTextOutput(outputId = "planner_volume"))
)
Try this code, it looks better to me
fluidRow(
column(3,
tagList(
tags$style(type = 'text/css','#avg_planned_miles .irs-grid-text {font-size: 12px}'), #the grid numbers size
div(id = 'avg_planned_miles', style='font-size: 16px;', #label font size
sliderInput(inputId = "avg_planned_miles", label = "Average Planner Miles\n", min = 5, max = 50, value = 9, step = 0.1)
)#div
)#tags
),
column(3,
tagList(
div(id = 'batch_pct',
style='position:absolute; top:10px; right:5px;', #add margin space
textInput(inputId = "batch_pct", width = 280,
label = "Batch%", value = "0.5")
)
)
),
column(3, p(strong("Volume")), #bold font to match the other fields
verbatimTextOutput(outputId = "planner_volume", placeholder = 1)
),
)
You can keep the sliderInput as it is in your code, I thought if the font sizes are bigger it looks better.
I have created the following UI using R shiny. The script is as follows.
The first part deals with the sidebar layout.
ui <- fluidPage(
titlePanel("Graphingtool"),
h3("DB"),
hr(),
fluidRow(
column(12,
fluidRow(
column(3,
fileInput("file1", 'DB',
multiple = TRUE,
accept = c("xlsx/xls",".xls",".xlsx"))),# We have added the formats here- will load excel alone- in case csv/txt needed amend here
column(5,
column(4,downloadButton(outputId = "Downloaddata", label = "Downloader"))
)
),
fluidRow(
column(3,
textInput(inputId = 'T',label = 'T'),
textInput(inputId = 'C',label = 'C'),
textInput(inputId = "P", label = "P"),
column(2, offset = 2,
actionButton(inputId = "CLS", label = "CLS"))
),
column(5,
textInput(inputId = "P", label = "P"),
textInput(inputId = "Y", label = "Y"),
numericInput(inputId = "Numberinput", label = "Ninput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)),
fluidRow(
column(3,
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Reg",
"Log" = "Log reg"))),
column(5,
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear reg",
"Log" = "Log reg")))
),
fluidRow(
column(5,
sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100,
step = 2.5, value = 1))) ) )
Here we create the main panel
,mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Table", tableOutput("table"))
)))
server<-function(input, output){reactive({})}
shinyApp(ui, server)
I Have created the main panel. However, the Panel with two tabs is opening under the sidebar panel and not on the right hand side of the panel.
The script works but is it possible to open the main panel on the right of the sidebar panel. I request someone to guide me here.
Take a look on this if this okay or not for you..
library(shiny)
ui <- fluidPage(
titlePanel("Graphingtool"),
h3("DB"),
hr(),
sidebarLayout(
sidebarPanel(
fluidRow(
column(5,
ailgn="center",
fileInput("file1", 'DB',
multiple = TRUE,
accept = c("xlsx/xls",".xls",".xlsx"))),# We have added the formats here- will load excel alone- in case csv/txt needed amend here
column(5,
ailgn="center",
HTML('<br/>'),
column(4,downloadButton(outputId = "Downloaddata", label = "Downloader"))
)
),
fluidRow(
column(5,
ailgn="center",
textInput(inputId = 'T',label = 'T'),
textInput(inputId = 'C',label = 'C'),
textInput(inputId = "P", label = "P"),
column(2, offset = 2,
ailgn="center",
actionButton(inputId = "CLS", label = "CLS"))
),
column(5,
ailgn="center",
textInput(inputId = "P", label = "P"),
textInput(inputId = "Y", label = "Y"),
numericInput(inputId = "Numberinput", label = "Ninput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)),
HTML('<br/>'),
fluidRow(
column(5,
ailgn="center",
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Reg",
"Log" = "Log reg"))),
column(5,
ailgn="center",
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear reg",
"Log" = "Log reg")))
),
fluidRow(
column(5,
ailgn="center",
sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100,
step = 2.5, value = 1)))
)
,mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Table", tableOutput("table"))
)))
)
server<-function(input, output){reactive({})}
shinyApp(ui, server)
You can tweak the size by adjusting column
I would like to show in UI only the first row (currently fluidRow) with device, color and linetype if user chooses number one, two first rows if user chooses number two and so on.
How do I add this kind of condition. I tried conditionalPanel but I failed there.
Tried to make a minimal reproducible example:
library(shiny)
shinyApp(
ui <- fluidPage(
fluidRow(
column(2, offset = 1,
selectInput(inputId = "number",
label = "Number:",
choices = list(
"One data set" = "1",
"Two data sets" = "2",
"Three data sets" = "3"))
)
),
fluidRow(
column(2,
selectInput(inputId = "dev1",
label = "Device:",
choices = list("Device 1", "Device 2"))
),
column(2,
selectInput(inputId = "col1",
label = "Color:",
choices = list("black", "red", "blue"))
),
column(2,
selectInput(inputId = "lty1",
label = "Linetype:",
choices = list("solid", "dashed"))
)
),
fluidRow(
column(2,
selectInput(inputId = "dev2",
label = "Device:",
choices = list("Device 1", "Device 2"))
),
column(2,
selectInput(inputId = "col2",
label = "Color:",
choices = list("black", "red", "blue"))
),
column(2,
selectInput(inputId = "lty3",
label = "Linetype:",
choices = list("solid", "dashed"))
)
)
),
server <- function(input, output) {})
Tell me if this needs more clarifying.
solution using server side logic, client side (JS) is also an option however this seems more natural given the platform in R and also it offers more control.
library(shiny)
library(shinyFiles)
shinyApp(
ui = fluidPage(
fluidRow(
column(2, offset = 1,
selectInput(inputId = "number",
label = "Number:",
choices = list(
"One data set" = "1",
"Two data sets" = "2",
"Three data sets" = "3"))
)
),
uiOutput('dynamic_selections')
),
server = function(input, output) {
observeEvent(input$number,{
output$dynamic_selections = renderUI({
lapply(1:as.integer(input$number),function(i){
fluidRow(
column(2,
selectInput(inputId = sprintf("dev%s",i),
label = "Device:",
choices = list("Device 1", "Device 2"))
),
column(2,
selectInput(inputId = sprintf("col%s",i),
label = "Color:",
choices = list("black", "red", "blue"))
),
column(2,
selectInput(inputId = sprintf("lty%s",i),
label = "Linetype:",
choices = list("solid", "dashed"))
),
column(2,
shinyFilesButton(id=sprintf("file%s",i), label='File:',title = 'Select File',multiple=FALSE, buttonType = "default", class = NULL)
)
)
})
})
lapply(1:as.integer(input$number),function(i){
shinyFileChoose(input, sprintf("file%s",i), roots=c(wd='.'), filetypes=c('', 'txt'))
})
})
})
EDIT: it has been highlighted that in some scenarios the file chooser box is not populated. Two things could go wrong
JS cannot read date attribute of folder/file therefore array is populated with null and errors when trying string split:
var mTime = data.files.mtime[i].split('-')
as a temp solution this can be avoided using restrictions parameter to exclude problematic folders/files?
When shinyFilesButton() is rendered via renderUI and server logic then fileChooser fails to populate but without any JS error, needs to be investigated further
I have a shiny app that have 2 bar charts and one heat chart, they have the same x axis (year), I want the years to be aligned in all the plots, but I don't know how to do it. below is my UI code:
ui = fluidPage(
titlePanel("Global Terrorism, is it getting worse?"),
tabsetPanel(
tabPanel("Plot", fluid = TRUE,
sidebarLayout(
sidebarPanel(radioButtons(
inputId="radio",
label="Variable Selection Type:",
choices=list(
"All Countries",
"Select a Country"
),
selected="All Countries")
,conditionalPanel(
condition = "input.radio != 'All Countries'",
selectInput("Country", "Select Country", choices = sort(unique(mydat$Country)), selected = "Iraq"),
sliderInput("freq", "Minimum Frequency:",min = 1, max = 50, value = 15),
sliderInput("max", "Maximum Number of Words:", min = 1, max = 100, value = 100)
), width=2),
mainPanel(fluidRow(
column(8, plotlyOutput("trendbarPlot", height = "200px",width = 845)),
column(8, plotlyOutput("trendheatrPlot", height = "300px",width = 845)),
column(2, plotOutput("WordCloud", height = "200px",width = 400)),
column(8, plotlyOutput("trendstakbarPlot", height = "200px",width = 895))
)
)
)
),
tabPanel("Map", fluid = TRUE,
sidebarLayout(
sidebarPanel(sliderInput("year", "Select Year:", min = 1968, max = 2009, value = 2009, sep='')),
mainPanel(
htmlOutput("Attacks")
)
)
)
)
I am working with shiny to do un R web application, the application is composed with a sidebarpanel on the left of the mainpanel (with 2 tabspanel) and another sidebarpanel below.
I want to keep the bottom sidebarpanel for the first mainpanel but removing it for the second.
The code looks like :
sidebarPanel(
wellPanel(
fileInput('file1', 'Choisissez les data service ?',
accept = c('text/csv', 'text/comma-separated-values',
'text/tab-separated-values', 'text/plain',
'.csv', '.tsv', 'RData'
)
)
),
wellPanel(
selectInput(inputId = "fonction.de",
label = "En fonction de ?",
choices = fonctions.de,
selected = "perimetre_commercial_estime"
),
selectInput(inputId = "perimetre",
label = "Perimetres commercial",
choices = perimetres,
selected = "2-HDM MARCHAND",
multiple = TRUE
),
checkboxInput(inputId = "case1", label = "Tous perimetres", value = FALSE),
selectInput(inputId = "ae",
label = "AE",
choices = aes,
selected = "AE Paris",
multiple = TRUE
),
checkboxInput(inputId = "case2", label = "Tous AE", value = FALSE),
selectInput(inputId = "segment",
label = "Segment commercial",
choices = segments,
selected = "Premium",
multiple = TRUE
),
checkboxInput(inputId = "case3", label = "Tous segments", value = FALSE)
)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Graphiques",
plotlyOutput("my.chart")),
tabPanel("Tables",
dataTableOutput("my.table"),
htmlOutput("my.text1"))
)
),
sidebarPanel(
selectInput(inputId = "abscisse",
label = "Abscisse",
choices = abscisses,
selected = "",
multiple = FALSE
),
selectInput(inputId = "ordonnee",
label = "Ordonnee",
choices = ordonnees,
selected = "",
multiple = FALSE
)
),
sidebarPanel(
img(src="Dymetryyy.jpg", height = 150, width = 350)
)
)
)
For people who are facing the same problem, you have to use conditionalPanel to solve it.
mainPanel(
tabsetPanel(id = "bab",
type = "tabs",
tabPanel(value = "graphiques",
"Graphiques",
plotlyOutput("my.chart")),
tabPanel(value = "tables",
"Tables",
dataTableOutput("my.table"),
htmlOutput("my.text1"))
)
),
conditionalPanel(condition = "input.bab == 'graphiques'",
sidebarPanel(
selectInput(inputId = "abscisse",
label = "Abscisse",
choices = abscisses,
selected = "",
multiple = FALSE
),
selectInput(inputId = "ordonnee",
label = "Ordonnee",
choices = ordonnees,
selected = "",
multiple = FALSE
)
),
sidebarPanel(
img(src="dymetryyy", height = 150, width = 350)
)
)