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
Related
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)
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)
)
)
library(shiny)
dataset <- new_historydata
shinyUI(fluidPage(
title = 'MEEDA v2.0',
sidebarLayout(
sidebarPanel(
tabsetPanel(type= "tabs",
tabPanel(("Historydata"),
fluidRow(
column(4,
selectInput("Costs", "Select Type :", c("All",
list( "total_cost"= 1, "lease_cost" = 2)),selected = "All", multiple= T),
selectInput("Variables", "Select Variables :", c( "All",
names(new_historydata)), selected = "All", multiple= T),
# List of devices in the data
selectInput("equipcategory", "Select Device :", c("All",
levels(historydata$equipmentcategoryx)),selected = "All", multiple= T))
),
fluidRow(
dataTableOutput("table1"))
),
tabPanel(("Plot"),
plotOutput('plot1'),
fluidRow(
title = "Variable Comparison",
hr(),
column(3,
h4("Variable Comparison"),
sliderInput('sampleSize', 'Sample Size',
min=1, max=nrow(dataset),
value= min(1000, nrow(dataset)),
step=500, round=0),
br(),
),
column(4, offset = 1,
selectInput('x', 'X', names(dataset)),
selectInput('y', 'Y', names(dataset), names(dataset[[1]]))
)
)),
tabPanel(("Calculations"),
helpText("Module Under Construction"),
fluidRow(
dataTableOutput("table2"),
))
)
)
)
))
I have a couple of questions regarding R shiny Dashboard.
ui.R
library(shinydashboard)
library(shiny)
dashboardPage(
dashboardHeader(title = 'Test Interface'),
dashboardSidebar(width = 600,
h3('-------Input Data-------'),
fluidRow(
column(6, div(style = "height:10px"), fileInput(inputId = 'FileInput', label = 'Upload Input:', accept = c('csv','tsv','txt'))),
column(2, div(style = "height:3px"), checkboxInput(inputId = 'header', label = 'Header', value = FALSE)),
column(2, div(style = "height:12px"), radioButtons(inputId = 'sep', label = 'Separator', choices = c(comma=',',tab="\t",space=' '), selected = ","),offset = 1)
),
fluidRow(column(6, div(style = "height:1px"), fileInput(inputId = 'FileInput1', label = 'Upload Second Input:'))),
br(),
h3('-------Select Foreground-------'),
fluidRow(
column(5, div(style = "height:17px"), radioButtons(inputId = 'cutoff', label = 'Selection', choices = c('Up'='pos','Down'='neg','Both'='both'))),
br(),
column(3, div(style = "height:1px"), textInput(inputId = 'fc', label = "Fold Change", value = '0')),
column(3, div(style = "height:1px; margin-left:10cm"), height = 6,textInput(inputId = 'pvalue', label = "Adj. Pvalue",value = '0.05'))
),
fluidRow(column(2, h1(" "), actionButton(inputId = 'select', label = "Select Data"))),
fluidRow(column(5, div(style = "height:25px;font-color:blue"), downloadButton('download', 'Download Plot')))),
dashboardBody(
tabsetPanel(type="tabs", id = "tabvalue",
tabPanel(title = "Input Table", value = 'tab1', DT::dataTableOutput('table')),
tabPanel(title = "Plot", value = 'tab7', plotOutput('plot',width = 800,height = 800)))))
server.R
library(shiny)
shinyServer(function(input, output, session){
})
I couldn't figure out how to add a vertical scroll bar to the dashboardSidebar. In my actual app, the last elements are not visible when I run the app.
Thanks!
I ran into this and came up with the following hack (and I do mean hack).
shinyDashboard(
tags$head(
tags$style(HTML(".sidebar {
height: 90vh; overflow-y: auto;
}"
) # close HTML
) # close tags$style
), # close tags#Head
# ...
The 90vh sets the sidebar height at 90% of the viewport height. You may want to adjust this to taste. Too large a percentage and some of the sidebar still drops below the horizon; too small a percentage and the sidebar ends noticeably before the main body (with the scrollbar appearing prematurely).