Why cannot I put a picture into the shiny app through img()? - r

My code is following:
ui <- fluidPage(
titlePanel("My Shiny App"),
sidebarLayout(
sidebarPanel(
h4("Installation"),
p("Shiny is available on CRAN, so you can install it on the usual way from your R console:"),
div("install packages('shiny')", style="color:red"),
img(src="C:/Users/asus/Desktop/App-1/rstudio.png", height=70, width=200)
),
mainPanel()
)
)
The picture does not appear properly. Only an empty box appears where the picture should appear.

Related

App not updating PDF displayed in tag$iframe

I have a PDF file that is constantly being updated and overwritten. It is saved in the www directory of the Shiny working directory. The problem is that the changes aren't being displayed in the app. The app still displays the first version of the pdf.
I originally had everything in the UI. I used tags$iframe in the ui.r code with the src pointing directly to the pdf file in the www directory.
Then I noticed that the pdf wasn't updating, so I tried to make an action button that when pushed would run the tags$iframe and display the pdf. This did not solve the problem. The updates in the pdf file are still not being displayed.
First attempt with everything in the UI
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h3("Title")
),
mainPanel(
tabsetPanel(
tabPanel("Tab 1",
tags$iframe(style="height:1200px; width:100%; scrolling=yes",
src="PDF1.pdf"))
)
)
)
)
server <- function(input, output,session){
}
shinyApp(ui, server)
Second attempt with the action button
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h3("Title")
),
mainPanel(
tabsetPanel(
tabPanel("Tab1",
sidebarLayout(
sidebarPanel(
actionButton("refresh_1", "Refresh PDF")
),
mainPanel(
uiOutput("Show_PDF1")
)
)
)
)
))
)
server <- function(input, output,session){
observeEvent(input$refresh_1, {
output$Show_PDF1 <- renderUI({
tags$iframe(style="height:1200px; width:100%; scrolling=yes", src="PDF1.pdf")
})
})
}
shinyApp(ui, server)
I am hosting the app on a non pro version of shiny server, and accessing it with chrome. To recreate the problem you can put any pdf file into the /srv/shiny-server/www directory with the name PDF1.pdf, and access the app. Then overwrite PDF1.pdf with another pdf file and run the app again. You will see that the app is still displaying the original PDF1.pdf file.

Giving Titles to side plots in Shiny with Fluidrow

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)

Shiny rendering googleVis HTML raw code

I used googleVis to generate a chart object (x) then outputted it as:
cat(x$html$chart, file="y.html")
How do I input this raw .html file into a Shiny server.R and then get it to render properly on the ui? I can't find anything. I've tried with
y <- readLines("y.html")
output$Plot = renderHTML(HTML(y))
and
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
...
),
mainPanel({
htmlOutput("Plot")
}
)
)
))
but this just generates a blank area. I omitted sidebarPanel because I know that works with my rendergVis() code that I was running.
Anyone know how to do what I'm trying to do?

Shiny and GoogleVis in Popup window

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")
})
})

how do you integrate 2 different shiny apps in one

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 :)

Resources