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)
Related
I am trying to build a simple To do list app using Shiny, the application is very simple, there's a textInput where I put things I want to do, and submit it, and it creates a checkbox. What I want to achieve is, if I check the box, there will be a text on the right side that says: "you have done XXX", the XXX is the information of the checkbox.
So far, I have managed to figure out how to insert a checkbox back into the UI however, I have problems in: writing the party of the code that once the checkbox is checked, generate a text which says " you have done XXX"
The two main difficulties is : 1. listen to the inserted UI (each checkbox needs a special id, but I can't write logic in the server components that has indeterministic checkbox id. Also, I can figure out a way to extract the content of the checkbox from the server side, the input$checkbox only gives me true or false value.
This is the code I am working on so far, I am wondering if this functionality is achievable using Shiny-R?
ui <- fluidPage(
theme = bs_theme(version = 4, bootswatch = "sketchy"),
titlePanel("A simple todo App"),
sidebarLayout(
sidebarPanel(
# Date configuration
dateInput("date", label = "Date Configuration"),
# Things to do
h3("Daily Todo", id="start", style = "color:grey", align = "center"),
checkboxInput("checkbox","Submit One Job Application"),
textInput("todo", label = "Other things to do"),
actionButton("todoBnt", label = "Submit"),
br(),
br(),
textInput("learnt", label = "Key things learnt"),
actionButton("learntBnt", label = "Submit")),
mainPanel(
h1(textOutput("timing"), align = "center"),
h1("What have I done",align = "center"),
verbatimTextOutput("value"),
h1("What have I learnt", align = "center"),
h2(textOutput("selected_var"),align = "center"),
p(textOutput("summary"),align="center"))
)
)
server <- function(input, output) {
inserted <- c()
observeEvent(input$todoBnt, {
insertUI(
selector = "#start",
where = "afterEnd",
ui = checkboxInput("chekcbox",input$todo)
)
})
output$timing <- renderText({
paste0("Today is ", as.character(input$date))
})
output$value <- renderText({ input$checkbox }) ##this gives "TRUE" value, I don't think it's right.
output$summary <- renderText({
paste0("I have learnt to ", input$learnt, "!")
})
}
shinyApp(ui = ui, server = server)
I have tried to search answer online, but I think the checkbox in Shiny-R is mainly used to filter graphs etc... So I am not sure if the function I want is actually achievable using the langague. Please help!
Instead of inserting each checkbox separately one option would be to switch to a checkboxGroupInput which you could update in your observeEvent. Doing so makes it easy to get a list of things you have done. However, doing so requires to track the things to do for which I use a reactiveVal choices which gets updated each time a new item is added to the to-do list:
library(shiny)
library(bslib)
ui <- fluidPage(
theme = bs_theme(version = 4, bootswatch = "sketchy"),
titlePanel("A simple todo App"),
sidebarLayout(
sidebarPanel(
# Date configuration
dateInput("date", label = "Date Configuration"),
# Things to do
h3("Daily Todo", id="start", style = "color:grey", align = "center"),
checkboxGroupInput("checkbox", label = "", choices = "Submit One Job Application"),
textInput("todo", label = "Other things to do"),
actionButton("todoBnt", label = "Submit"),
br(),
br(),
textInput("learnt", label = "Key things learnt"),
actionButton("learntBnt", label = "Submit")),
mainPanel(
h1(textOutput("timing"), align = "center"),
h1("What have I done",align = "center"),
verbatimTextOutput("value"),
h1("What have I learnt", align = "center"),
h2(textOutput("selected_var"),align = "center"),
p(textOutput("summary"),align="center"))
)
)
server <- function(input, output) {
choices <- reactiveVal("Submit One Job Application")
inserted <- c()
observeEvent(input$todoBnt, {
selected <- input$checkbox
choices(c(choices(), input$todo))
updateCheckboxGroupInput(inputId = "checkbox", choices = choices(), selected = selected)
updateTextInput(inputId = "todo", value = "")
})
output$timing <- renderText({
paste0("Today is ", as.character(input$date))
})
output$value <- renderText({
paste(input$checkbox, collapse = "\n")
})
output$summary <- renderText({
paste0("I have learnt to ", input$learnt, "!")
})
}
shinyApp(ui = ui, server = server)
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 Shiny DashboardPlus and I want the sidebar-mini to display only icons. The problem is that text appears also.
Same issue with shiny dashboard also.
The code for creating the sidebar menu below:
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("DASHBOARD1", tabName = "Spectrum", icon = icon("table")
), #menuItem
menuItem("DASHBOARD2", tabName = "LTE", icon = icon("mobile-alt"))
)),
See it here:
I think there might be version issue as it all works fine for me:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("DASHBOARD1", tabName = "Spectrum", icon = icon("table")
), #menuItem
menuItem("DASHBOARD2", tabName = "LTE", icon = icon("mobile-alt"))
)),
body = dashboardBody(),
title = "TEST"
),
server = function(input, output) { }
)
Here is the sample session Info:
R version 3.5.2 (2018-12-20)
shiny_1.2.0
shinydashboard_0.7.1
shinydashboardPlus_0.6.0.9000
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
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)