I'm new to RShiny and I decided to create my first App.
When I lauch my app with this command it executes right away and everything is fine.
shinyApp(ui, server)
But when I'm trying to deploy my app to the Shinyapps.io servers I have this error
Error: Unhandled Exception: Child Task 547685425 failed: Error parsing
manifest: Bundle does not contain manifest file: data/données.xlsx
It looks like Shiny can't find my document données.xlsx which is where I'm reading data for my apps but the first thing I do in my code is setting my directory.
Here is my Code :
setwd("C:/Users/Baillargeon/Desktop/R_PROG/RShiny_test")
library(shiny)
library(shinydashboard)
library(DT)
library(rsconnect)
library(ggplot2)
library(plotly)
library(dplyr)
library(xlsx)
donnees <- read.xlsx("data/données.xlsx", sheetName = "donnees", encoding = "UTF-8")
[...]
ui <- dashboardPage(
dashboardHeader(title = "Employés"),
dashboardSidebar(
sidebarMenu(
menuItem("Jeu de données",tabName="Donnees",icon=icon("database")),
menuItem("Graphiques",tabName="graph",icon=icon('signal'))
)
),
dashboardBody(
tabItems(
tabItem(tabName="Donnees",
h2("Données"),
DT::dataTableOutput("donnees")
),
tabItem(tabName = "graph", h2("Graphiques"),
fluidRow(
box(plotlyOutput("plot_sites")),
box(plotlyOutput("plot_sexe"))
)
)
)
)
)
server <- function(input,output){
output$donnees = DT::renderDataTable({
donnees
})
output$plot_sites <- renderPlotly({
plot_ly(final_sites, labels= final_sites$Site, values= final_sites$Freq, type="pie",
textposition = 'inside',
textinfo = 'label+percent',
showlegend = FALSE
) %>%
layout(title="Répartition des employés selon l'arondissement")
})
output$plot_sexe <- renderPlotly({
plot_ly(final_sexe, labels= final_sexe$Sexe, values= final_sexe$Freq, type="pie",
textposition = 'inside',
textinfo = 'label+percent',
showlegend = FALSE
) %>%
layout(title="Répartition des employés selon leurs Sexe")
})
}
shinyApp(ui, server)
rsconnect::deployApp("C:/Users/Baillargeon/Desktop/R_PROG/RShiny_test")
Does anyone know how to solve this error ?
Thanks
remove setwd("C:/Users/Baillargeon/Desktop/R_PROG/RShiny_test") as first line.
When you are deploying on shinyapps.io , it is a linux environment. so C:/ makes no sense.
Moreover, by default your working directory is where your ui.R and server.R are located. So, your data folder path should be relevant to that. Which looks like so from your code.
read documentation 9.4 “Disconnected from server” messages
Hope it helps
Related
I want to insert a fixed hyperlink in a shiny::info pop up
library(shiny)
library(shinyjs)
library(shinydashboard)
ui <- (
fluidPage(
useShinyjs(),
div(
id = "main_page",
fluidRow( # -------------------------------------------------------
infoBox(title=NULL, icon=shiny::icon(""), subtitle = HTML("<a id=\"infobutton\"
href=\"#\" class=\"action-button\"><i class=\"fa fa-info-circle\"></i></a>"))
)
)
)
)
server <- (
function(input, output, session) {
observeEvent(input$infobutton, {
shinyjs::info("It's me Mario")
})
}
)
shinyApp(ui = ui, server = server)
I've tried with a TagList but the pop up just display what's inside the tagList
shinyjs::info(tagList("It' me Mario:", a("Mario", href="https://en.wikipedia.org/wiki/Mario")))
Thanks !
You cannot (or should not) be able to insert HTML into there. It only supports plain text.
shinyjs::info() is running the javascript alert() function - here's the official documentation for it.
Notice the message parameter is:
A string you want to display in the alert dialog, or, alternatively, an object that is converted into a string and displayed.
It's not meant to accept HTML. I'm honestly very surprised that it's able to parse HTML within RStudio, browsers are supposed to only show plain text. If you want to show a pop up message with HTML you need to use something more advanced like shinyalert package or shiny modals.
You can directly generate the needed HTML with HTML:
library(shiny)
library(shinyjs)
library(shinydashboard)
ui <- (
fluidPage(
useShinyjs(),
div(
id = "main_page",
fluidRow( # -------------------------------------------------------
infoBox(title=NULL, icon=shiny::icon(""), subtitle = HTML("<a id=\"infobutton\"
href=\"#\" class=\"action-button\"><i class=\"fa fa-info-circle\"></i></a>"))
)
)
)
)
server <- (
function(input, output, session) {
observeEvent(input$infobutton, {
shinyjs::info(HTML("<p>It's me Mario:</p> <a href='https://en.wikipedia.org/wiki/Mario'>Mario</a>"))
})
}
)
shinyApp(ui = ui, server = server)
I'am using the R package plotly in my shiny application.
Here is a small example:
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("event")
)
server <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
output$plot <- renderPlotly({
plot_ly(mtcars, x = ~mpg, y = ~wt)
})
output$event <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover on a point!" else d
})
}
shinyApp(ui, server)
When I click on the icon to download the graphic, the name of the graphic is "newplot":
How can I change the name "newplot(27)" by for example "ResultDNA(27)"
Thanks.
Currently there are two solutions:
By using export function in plotly
App1 <- plot_ly()
export(App1 , file = "ResultDNA(27).png")
You can 1st save the image in HTML and then in desired format using htmlwidgets
App2 <- plot_ly(...)
htmlwidgets::saveWidget(App2, file = "ResultDNA(27).html")
I have created a Shiny App using Package 'shinydashboard' as below :
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("ABC", tabName="ABC", icon=icon("line-chart"), selected=TRUE),
menuItem("ABC1", tabName="ABC1", icon=icon("line-chart"), selected=FALSE)
),
conditionalPanel("input.tabs == 'ABC'",
fluidRow(
column(11, offset = 1, h5((' Note')))
)
),
conditionalPanel("input.tabs == 'ABC1'",
fluidRow(
column(11, offset = 1, style = "height:20px; color:rgb(30,144,255);", h1((' Update')))
)
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "ABC",br())
),
tabItems(
tabItem(tabName = "ABC1",br())
)
)
ui = dashboardPage(
dashboardHeader(title = "ABC"),
sidebar,
body
)
server = function(input, output){}
shinyApp(ui = ui, server = server)
However I have noticed a strange behaviour that, when I run the App, initially the comment 'Note' in "input.tabs == 'ABC'" is not visible. However when I click on "input.tabs == 'ABC1'" and then 'ABC', the 'Note' comment becomes visible.
Can somebody points me where I went wrong in above code?
Any help will be highly appreciated.
Thanks,
It seems that we introduced this bug in the newest version of shinydashboard. Sorry! I'll try to fix it soon. You can keep track of the progress here: https://github.com/rstudio/shinydashboard/issues/214.
Update (9 June 2017): This is now fixed on the development version of shinydashboard. Your original code should run just fine if you install shinydashboard from github:
devtools::install_github("rstudio/shinydashboard")
In the meantime, a couple of things:
You don't need to use selected = FALSE.
If the menuItem() that you want to start selected is the first one (like in the example you posted above), also remove selected = TRUE and your problem goes away. This is just a workaround to get your app working now. When this bug is solved, there will be no difference in having selected = TRUE or nothing in the first menuItem().
A more general workaround for now (works no matter which menuItem() you want to start selected) is to use a dynamic sidebar menu:
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
sidebarMenuOutput("menu"),
conditionalPanel("input.tabs == 'ABC'",
fluidRow(
column(11, offset = 1, h5((' Note')))
)
),
conditionalPanel("input.tabs == 'ABC1'",
fluidRow(
column(11, offset = 1, style = "height:20px; color:rgb(30,144,255);", h1((' Update')))
)
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "ABC",br())
),
tabItems(
tabItem(tabName = "ABC1",br())
)
)
ui = dashboardPage(
dashboardHeader(title = "ABC"),
sidebar,
body
)
server = function(input, output){
output$menu <- renderMenu({
sidebarMenu(id="tabs",
menuItem("ABC", tabName="ABC", icon=icon("line-chart"), selected=TRUE),
menuItem("ABC1", tabName="ABC1", icon=icon("line-chart"))
)
})
}
shinyApp(ui = ui, server = server)
I am new to shiny. When I made my project, I need to hide the dashboardHeader in server side.
In the shinydashboard website, I found the code dashboardHeader(disable = TRUE). I tried this, but it was not work.
However, I tried use shinyjs to solve the problem.
<code>
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(
extendShinyjs(text = 'shinyjs.hidehead = function(params) {
$("header").addClass("sidebar-collapse") }'),
),
dashboardSidebar(),
dashboardBody(
actionButton("button","hide_header",width = 4 )
)
)
server <- function(input, output) {
observeEvent(input$button, {
js$hidehead()
})}
shinyApp(ui, server)</code>
I guess you already known, it still not worked.
Any ideas for my case?
Shinyjs is a great library. The problem with your code is that you need first to initialize shinyjs with shinyjs::useShinyjs() and put it inside the dashboarBody function. Also, to hide/show the header you don't need to add the class "sidebar-collapse" that is actually for the sidebar. You only need to add style="display:none" to hide the header, and remove it to show the header. Below is your code modified to hide/show the header. The JS code used is very simple and it receive the parameter to add directly from the js$hidehead() function.
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
# initialize shinyjs
shinyjs::useShinyjs(),
# add custom JS code
extendShinyjs(text = "shinyjs.hidehead = function(parm){
$('header').css('display', parm);
}"),
actionButton("button","hide header"),
actionButton("button2","show header")
)
)
server <- function(input, output) {
observeEvent(input$button, {
js$hidehead('none')
})
observeEvent(input$button2, {
js$hidehead('')
})
}
shinyApp(ui, server)
I am creating a test page over #RMarkdown and trying to add #Shiny content in it. While knitting to HTML I am receiving the following error.
Error in appshot.shiny.appobj(list(httpHandler = function (req) :
appshot of Shiny app objects is not yet supported. Calls:
... in_dir -> do.call -> -> appshot.shiny.appobj Execution
halted
Please help. What are the packages that would be required to run shiny app in #RMarkdown? Or what should be done to successfully run #shiny on #RMarkdown?
Below is my test code.
```{r setup, include=TRUE, echo=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
```
```{r tabs, echo=FALSE}
shinyApp(
ui = fluidPage(
tabsetPanel(
id = 'dataset',
tabPanel('diamonds', DT::dataTableOutput('mytable1')),
tabPanel('mtcars', DT::dataTableOutput('mytable2'))
)
),
server = function(input, output) {
},
options = list(height = 500)
)
```
you need to add to the header of the rmd
runtime: shiny