I am trying to create a 2x2 grid with 4 buttons.
The label of each button should be above the actual button.
Is there such an option in R shiny?
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$h1("Pretty radio buttons"),
br(),
fluidRow(
column(
width = 4,
prettyRadioButtons(
inputId = "radio1",
label = "Click me!",
choices = c("Click me !", "Me !", "Or me !", 'Or me!')
),
verbatimTextOutput(outputId = "res1"),
br(),
)
)
)
server <- function(input, output, session) {
output$res1 <- renderPrint(input$radio1)
}
if (interactive())
shinyApp(ui, server)
Related
Is there way to adjust the width of a well panel as shown in the image below? At the bottom is the code, if the user clicks the "Delete column" action button a conditional panel renders underneath; clicking of any other action button causes the conditional panel to disappear. I'd like the conditional panel to be surrounded in a well panel and am trying to format it nicely.
My guess is this requires some CSS.
Code:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
br(),
fluidRow(
column(2,actionButton("addCol","Add column")),
column(2,actionButton("delCol","Delete column")),
column(2,actionButton("savTbl","Save table")),
column(2,actionButton("clrTbl","Clear table")),
br(),
),
br(),
shinyjs::hidden(
div(id="delPanel",
conditionalPanel(
condition="input.delCol > 0 && !output.hide_panel",
fluidRow(
wellPanel(
column(2,textOutput("delFlag")),
column(3,uiOutput("delCol2"))
)
),
style = "display: none;"
)
)
)
)
server <- function(input,output,session)({
observeEvent(input$delCol,{shinyjs::show("delPanel")})
observeEvent(input$addCol|input$savTbl|input$clrTbl,{shinyjs::hide("delPanel")})
output$delFlag <- renderText("Delete column:")
output$delCol2 <-
renderUI(
selectInput("delCol3",
label = NULL,
choices = c(1,2,3),
selected = "")
)
})
shinyApp(ui, server)
Below is a css solution, thanks to post Shiny wellpanel width:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
br(),
fluidRow(
column(2,actionButton("addCol","Add column")),
column(2,actionButton("delCol","Delete column")),
column(2,actionButton("savTbl","Save table")),
column(2,actionButton("clrTbl","Clear table")),
br(),
),
br(),
shinyjs::hidden(
div(id="delPanel",
conditionalPanel(
condition="input.delCol > 0 && !output.hide_panel",
fluidRow(tags$div(id="pane", # added
wellPanel(
column(2,textOutput("delFlag")),
column(3,uiOutput("delCol2")),
),
tags$style(type="text/css","#pane{font-size:14px;width:565px;}") # added
)
),
style = "display: none;"
)
)
)
)
server <- function(input,output,session)({
observeEvent(input$delCol,{shinyjs::show("delPanel")})
observeEvent(input$addCol|input$savTbl|input$clrTbl,{shinyjs::hide("delPanel")})
output$delFlag <- renderText("Delete column:")
output$delCol2 <-
renderUI(
selectInput("delCol3",
label = NULL,
choices = c(1,2,3),
selected = "")
)
})
shinyApp(ui, server)
I'm quite new to Shiny and I'm having a hard time to fix the following apparently simple example.
I have the following code:
library(shiny)
u <- fluidPage(
titlePanel("Simple Selectable Reactive Function"),
sidebarLayout(
sidebarPanel(),
mainPanel(
h2("Results"),
fluidRow(column(2,
selectInput("aa", "Choose a function", choices=c("sin","cos","exp"))
),
column(2,
textOutput(outputId = "outputText1")
)
)
))
)
s <- function(input,output){
output$outputText1 <- renderText({
paste("Sample text")
})
}
shinyApp(ui=u,server=s)
All I'm trying to do is to have "Sample text" aligned at the same height on the screen as the drop down box ("sin").
Right now, the words "Sample text" are aligned with the element label "Choose a function".
I checked ?textOutput but it doesn't seem to be very useful.
Thank you
One way is to wrap your textOutput(outputId = "outputText1") with a tags$div and add a top padding.
library(shiny)
u <- fluidPage(
titlePanel("Simple Selectable Reactive Function"),
sidebarLayout(
sidebarPanel(),
mainPanel(
h2("Results"),
fluidRow(column(2,
selectInput("aa", "Choose a function", choices=c("sin","cos","exp"))
),
column(2,
tags$div(textOutput(outputId = "outputText1"), style = "padding-top:30px;")
)
)
))
)
s <- function(input,output){
output$outputText1 <- renderText({
paste("Sample text")
})
}
shinyApp(ui=u,server=s)
Alternative use two fluidRow to make it more responsive.
In this case the label of the selectInput is set to NULL and e.g. a h5 element is used instead.
library(shiny)
u <- fluidPage(
titlePanel("Simple Selectable Reactive Function"),
sidebarLayout(
sidebarPanel(),
mainPanel(
h2("Results"),
fluidRow(column(2, h5(tags$b("Choose a function")))),
fluidRow(column(2, selectInput("aa", label = NULL, choices=c("sin","cos","exp"))),
column(2,textOutput(outputId = "outputText1")))
)
)
)
s <- function(input,output){
output$outputText1 <- renderText({
paste("Sample text")
})
}
shinyApp(ui=u,server=s)
I am currently developing a Shiny App. In that I am not getting the expected output. The expected output is
But the output I get is
This is the code used
ui.R
shinyUI(
dashboardPage(
dashboardSidebar(
sidebarMenu(
id = 'MENU', badgeColor = "aqua",
menuItem('VIEW', tabName = 'view'),
menuItem('EDIT',tabName = 'edit')
)
),
dashboardBody(
tabItems(tabItem(tabName = "edit",
uiOutput("moreControls"))))
server.R
shinyServer(function(input, output, session) {
output$moreControls <- renderUI({
wellPanel(
fluidRow(column(4,wellPanel(
wellPanel("PEOPLE", style = "background-color:#0ec3c6;border-color:#0ec3c6;text-align:center;color: white;font-size: 24px;font-style: bold ;padding: 12px;"),
style ="background-color:RGB(255,255,255); border-color:RGB(255,255,255);align:right;",
textInput('email', 'Enter Email_Id'),
textInput('fn', ' Enter First Name')))))})
})
Can anyone help me with this issue? Thanks in advance..
Below code will give you the required wellPanel layout.
Note: I didn't use your full code, just tried to achieve specified layout. So replace the code block if it solves your problem.
library(shiny)
ui <- fluidPage(
wellPanel(
fluidRow(column(4,
fluidRow(wellPanel("PEOPLE", style = "background-color:#0ec3c6;border-color:#0ec3c6;text-align:center;color: white;font-size: 24px;font-style: bold ;padding: 12px;")),
style = "background-color:RGB(255,255,255); border-color:RGB(255,255,255);align:right;",
fluidRow(column(4, "Enter Email-ID"), column(8, textInput(label = NULL, inputId = 'EmailID' ))),
fluidRow(column(4, "Enter First Name"), column(8, textInput(label = NULL, inputId = 'FirstName')))))))
server <- function(input, output, session) {
onSessionEnded(stopApp)
}
shinyApp(ui, server)
Consider the example below
ui.R:
library(shiny)
library(shinyjs)
shinyUI(
tabPanel("VIEW",
tabsetPanel(id="viewic",
tabPanel("view1",
fluidRow( column(2,
actionButton("button1", "BUTTON1")),
column(2,
actionButton("button2", "BUTTON2"))
))
tabPanel(" View2"))),
fluidRow(
uiOutput("ui1")
),
fluidRow(
uiOutput("ui2")
))
Server:
library(shiny)
library(shinyjs)
shinyServer(function(input, output,session){
observeEvent(
input$button1,
output$ui1 <- renderUI({isolate({
column(3,
selectInput("selectview1",
label = "Select Id",
choices = c("1","2","3")
))})}))
observeEvent(
input$button2,
output$ui2 <- renderUI({isolate({
column(3,
selectInput("selectview2",
label = "Select Id",
choices = c("4","5","6")
))})}))
})
How to reset the session,ie; when I press button1 the selectinput with id selectview1 appears and when I press the button2 the selectInput with id selectview2 defined inside it appears but the selectinput that appeared firstly when the button1 was clicked is also being displayed along with it and vice versa.I tried reset and toggle but it didn't worked properly.
EDIT: use conditionalPanel on your selectInputs. So something to the effect of:
conditionalPanel(condition = 'input.button1 % 2 > 0',
uiOutput("ui1")
)
This checks whether or not the value of your actionButton is even and only displays it when it is odd. So assuming the button starts at a 0 value, it will display after 1, 3, 5, 7... clicks.
I think this should work. Can you try it out?
If you just want to hide a button depending on a click, look into conditionalPanel() and wrap your button code (ui side) in that function.
http://shiny.rstudio.com/reference/shiny/latest/conditionalPanel.html
ui.R
library(shiny)
library(shinyjs)
shinyUI(
fluidPage(
tabPanel("VIEW",
tabsetPanel(id="viewic",
tabPanel("view1",
fluidRow( column(2,
actionButton("button1", "BUTTON1")),
column(2,
actionButton("button2", "BUTTON2"))
)),
tabPanel(" View2"))),
fluidRow(
uiOutput("ui1")
),
fluidRow(
uiOutput("ui2")
)))
server.R
library(shiny)
library(shinyjs)
shinyServer(function(input, output,session){
observeEvent(
input$button1,
output$ui1 <- renderUI({isolate({
output$ui2<-renderUI(
isolate({
dataTableOutput(NULL)
} ) )
column(3,
selectInput("selectview1",
label = "Select Id",
choices = c("1","2","3")
))})}))
observeEvent(
input$button2,
output$ui2 <- renderUI({isolate({
output$ui1<-renderUI(
isolate({
dataTableOutput(NULL)
} ) )
column(3,
selectInput("selectview2",
label = "Select Id",
choices = c("4","5","6")
))})}))
})
This code worked.
I have a shiny app where i want to hide or show some elements based on user input. This i tried to do by using conditionalPanel in shiny. However, it works only after pressing the submit button. I want to hide or show the textInput element without pressing the submit button. Below is an example what I tried.
UI.R
library(shiny)
shinyUI(fluidPage(
titlePanel("submitButton example"),
fluidRow(
column(3, wellPanel(
sliderInput("n", "N:", min = 10, max = 1000, value = 200,
step = 10),
checkboxInput("checkbox", label = "Message", value = FALSE),
conditionalPanel(
condition = "input.checkbox == true",
textInput("text", "Text:", "text here")),
submitButton("Submit")
)),
column(6,
plotOutput("plot1", width = 400, height = 300),
verbatimTextOutput("text")
)
)
))
Server.R
shinyServer(function(input, output) {
output$plot1 <- renderPlot({
hist(rnorm(input$n))
})
output$text <- renderText({
paste("Input text is:", input$text)
})
})
I want to show the textInput as soon as user checks the checkbox and hide it on uncheck without any dependency on submit button.
You can try
UI:
library(shiny)
shinyUI(fluidPage(
titlePanel("submitButton example"),
fluidRow(
column(3, wellPanel(
sliderInput("n", "N:", min = 10, max = 1000, value = 200,
step = 10),
checkboxInput("checkbox_1", label = "Message", value = FALSE),
uiOutput('test')
,actionButton("Submit",label ="Submit" )
)),
column(6,
plotOutput("plot1", width = 400, height = 300),
verbatimTextOutput("text")
)
)
))
server:
shinyServer(function(input, output,session) {
output$test=renderUI({
if(input$checkbox_1==T){
list(textInput("text", "Text:", "text here"),
numericInput("num","num",0), numericInput("num1","num1",0))}
})
observeEvent(input$Submit,{
output$plot1 <- renderPlot({
hist(rnorm(isolate(input$n)))
})
output$text <- renderText({
paste("Input text is:", isolate(input$text))
})
})
})