How to give titles in Shiny for two side plots, I am trying to do something like following, which is definitely giving me error
shinyUI(
titlePanel("Hello Shiny!"),
mainPanel(
fluidRow(
splitLayout(cellWidth(50%,50%),
tableOutput("Table1", tags$b("Title1")),
plotOutput("Plot",tags$b("Title2)))))
Here is the solution for you:
library(shiny)
ui <- basicPage(
fluidRow(
column(6,box("Title 1",tableOutput("Table1"))),
column(6,box("Title 2",plotOutput("Plot")))))
server <- function(input, output) {
}
shinyApp(ui, server)
It is enough if you just type the text in column container before ..output(..)
I have improved bit your code by replacing splitLayout() to column containers which divide/split the ui into two, same size containers (column(6)=50%) and addition of box(), so your outputs are held there and title will be attached to it (to the box)
Related
I'm using prettyCheckboxGroup from shinyWidgets within a sidebar panel in Shiny. Some of the items are unavoidably a bit long and so they extend out of the edge of the sidebar.
I'd like to know how to either wrap long text or limit the width for text to force it on to the next line.
I assumed that the width argument would achieve this but it only seems to effect the caption and not the choices text.
The standard checkboxGroupInput did this as standard so I'm wondering if I am missing something with the fancier ShinyWidgets version?
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
sidebarPanel(
width = 2,
uiOutput('boxpick')
)
)
server<- function(input, output) {
output$boxpick <- renderUI(
prettyCheckboxGroup('boxpick', 'Pick an item:',
choices= c('really really long',
'really really really really long',
'really really really really really really really really long')
)
)
}
shinyApp(ui,server)
This answer explains how can one disable/enable all UI elements in a Shiny app.
Among the two solutions given, the one I am interested in uses the shinyjs package (I'd rather not play with javascript directly).
My problem is that UI elements of the class downloadButton are not listed as elements of input.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tagList(
downloadButton("downloadBtn", "Download button"),
actionButton("printBtn", "Print and disable all members of input")
)
)
server <- function(input, output) {
observeEvent(input$printBtn, {
print (names(input))
for(n in names(input))
shinyjs::disable(id=n)
})
}
shinyApp(ui = ui, server = server)
When I click on the "Print all members of input", only "printBtn" is printed ("downloadBtn" is not).
Hence, since downloadButton is not a member of input, disabling it by looping over all the elements of input - and disabling them one by one does not work.
Is there an elegant workaround that can be used in order to disable all of the elements?
I'm new to Shiny and R in general and could do with some help!
I've been trying to get some googleVis outputs into Shiny without success. I can get gvis outputs for bubble, motion and scatter charts directly in R but not in a shiny app.
I've checked reference code from Mages and others but I don't get an output chart in Shiny.
I've stripped it back to its most basic but can't get the visualisation. Is there anyone who could give me a pointer on what I am doing wrong?
Thanks!
#UI.R
library(shiny)
library(googleVis)
shinyUI(fluidPage(
titlePanel("GoogleVis example"),
sidebarLayout(
sidebarPanel(
h4("GoogleVis and Shiny")
),
mainPanel(
htmlOutput("bubble")
)
))
)
#Server.R
library(shiny)
library(googleVis)
shinyServer(function(input, output, session){
Newyork=read.csv("data/Newyork.csv")
output$bubble<- renderGvis({
gvisBubbleChart(Newyork, idvar="County", xvar="Population", yvar="Crime.Rate")
})
})
I have two shiny apps with ui and server compoents. I need to create one app and be able to open the each application with tabs. Clicking on one tab will bring the app.
first app is like this:
ui <- pageWithSidebar(....)
server <- function(input, output,session) {....}
second app is something like this:
shinyUI(....)
server <- function(input, output, session) {.....}
How could I create one app and refer to these apps from tabs within one app?
As far as I know, this could be achieved in two ways.
Simple shiny app:
You can create tabs using tabPanel(title, ...) function and then wrapping all the tabPanel()s inside a tabsetPanel() function.
So, in your case you can put all the UI elements of your first app inside the first tabPanel('unique_title') and so on.
This will help you create multiple independently viewable sections.
You can refer these two links to know more
http://shiny.rstudio.com/reference/shiny/latest/tabPanel.html
As #Michal suggested, using shinydashboard:
shinydashnoard is another package that you will have to install in order to use this feature of shiny. It basically has a predefined structure with a header, a sidebar and a body.
The basic structure is shown below:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashbaordSidebar(),
dashboardBody()
)
server <- function(input,output,server){...}
Normally, dashboardSidebar() is used for navigation. However, it can contain menuItem() that behave like tabs in a tabPanel().
For your case, you can add multiple menuItem()s inside sidebarMenu() as shown below
Updated Code
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("first_app", tabName = "first_app"),
menuItem("second_app", tabName = "second_app")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "first_app",
h2("First App Content")
),
tabItem(tabName = "second_app",
h2("Second App Content"))
)
)
)
server <- function(input,output,server){}
shinyApp(ui,server)
This will create a basic dashboard page with 2 menu items.
You can also refer to link below to know more about the shinydashboard structure
https://rstudio.github.io/shinydashboard/structure.html
I hope this helps :)
I have two buttons in my U.i file
submitButton("Analysis"),width=6,downloadButton('downloadData', 'Download Data'))
Which gives the following output as the app
However I am trying to align these buttons so that the download data is right aligned and the analysis button is on the left, instead of how it looks now. How do i go about this?
You can do the following. Please look into shiny 4 small textInput boxes side-by-side also
library(shiny)
ui =fluidPage(
div(style="display:inline-block",submitButton("Analysis"),width=6),
div(style="display:inline-block",downloadButton('downloadData', 'Download Data'))
)
server = function(input, output, session){}
runApp(list(ui = ui, server = server))